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 < 2) { 12 printf("Usage:\n" 13 "test_tty_open [path]\n"); 14 return 0; 15 } 16 17 struct stat file_stat; 18 const char* path; 19 20 if (strnlen(argv[1], MAX_PATH) == MAX_PATH) { 21 printf("[FAIL] test_tty_open: path length is too long\n"); 22 return -1; 23 } 24 25 path = argv[1]; 26 27 // check presence of device node 28 if (-1 == stat(path, &file_stat)) { 29 printf("[FAIL] test_tty_open: file does not exist\n"); 30 return -1; 31 } 32 33 if (-1 == testOpenClose(path)) { 34 goto fail; 35 } 36 37 printf("[PASS] test_tty_open\n"); 38 return 0; 39 40fail: 41 printf("[FAIL] test_tty_open\n"); 42 return -1; 43}