1 2#include <stdio.h> 3#include <string.h> 4#include <sys/stat.h> 5#include "IOSerialTestLib.h" 6 7#define MAX_PATH 256 8 9int main(int argc, const char * argv[]) 10{ 11 if (argc < 3) { 12 printf("Usage:\n" 13 "test_tty_read_write [readpath] [writepath]\n" 14 "test_tty_read_write [readpath] [writepath] [message]\n"); 15 return 0; 16 } 17 18 struct stat file_stat; 19 const char* readpath; 20 const char* writepath; 21 const char* message = NULL; 22 23 if (strnlen(argv[1], MAX_PATH) == MAX_PATH) { 24 printf("[FAIL] test_tty_read_write: path length is too long\n"); 25 return -1; 26 } 27 if (strnlen(argv[2], MAX_PATH) == MAX_PATH) { 28 printf("[FAIL] test_tty_read_write: path length is too long\n"); 29 return -1; 30 } 31 32 if (argc == 4) { 33 if (strnlen(argv[3], MAX_PATH) == MAX_PATH) { 34 printf("[FAIL] test_tty_read_write: message is too long\n"); 35 } 36 else { 37 message = argv[3]; 38 } 39 } 40 41 readpath = argv[1]; 42 writepath = argv[2]; 43 44 // check presence of device node 45 if (-1 == stat(readpath, &file_stat)) { 46 printf("[FAIL] test_tty_read_write: file does not exist\n"); 47 return -1; 48 } 49 if (-1 == stat(writepath, &file_stat)) { 50 printf("[FAIL] test_tty_read_write: file does not exist\n"); 51 return -1; 52 } 53 54 if (-1 == testReadWrite(readpath, writepath, message)) { 55 goto fail; 56 } 57 58 printf("[PASS] test_tty_read_write\n"); 59 return 0; 60 61fail: 62 printf("[FAIL] test_tty_read_write\n"); 63 return -1; 64} 65 66