int main() { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(Semihost file system); MBED_HOSTTEST_START("MBED_A2"); pc.printf("Test the Stream class\n"); printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No")); char mac[16]; mbed_mac_address(mac); printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); LocalFileSystem local("local"); FILE *f; char *str = TEST_STRING; char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); // Write f = test_open("w"); test_write(f, str, str_len); test_close(f); // Read f = test_open("r"); test_read(f, buffer, str_len); test_close(f); // Check the two strings are equal MBED_HOSTTEST_RESULT((strncmp(buffer, str, str_len) == 0)); }
int main() { pc.printf("Test the Stream class\n"); printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No")); char mac[16]; mbed_mac_address(mac); printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); LocalFileSystem local("local"); FILE *f; char* str = TEST_STRING; char* buffer = (char*) malloc(sizeof(unsigned char)*strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); // Write f = test_open("w"); test_write(f, str, str_len); test_close(f); // Read f = test_open("r"); test_read(f, buffer, str_len); test_close(f); // Check the two strings are equal notify_completion((strncmp(buffer, str, str_len) == 0)); }
static void setup_interleaved(void) { JournalFile *one, *two; one = test_open("one.journal"); two = test_open("two.journal"); append_number(one, 1, NULL); append_number(two, 2, NULL); append_number(one, 3, NULL); append_number(two, 4, NULL); test_close(one); test_close(two); }
int run_close_test(void * f, int expected_errno, const char * condition){ int err; printf("testing close()..."); printf("%s", condition); printf("..."); err = test_close(f); if ( err < 0 ){ if ( expected_errno == 0 ){ fflush(stdout); perror("unexpected error"); return -1; } else if ( errno == expected_errno ){ printf("passed\n"); return -1; } } else { if ( expected_errno == 0 ){ printf("passed\n"); return 0; } else { printf("should have failed with %d\n", expected_errno); return 0; } } return -1; }
int testdomain() { int rc; int s; int op; size_t opsz; printf("test domain\n"); s = test_socket (AF_SP, NN_PAIR); opsz = sizeof (op); rc = nn_getsockopt (s, NN_SOL_SOCKET, NN_DOMAIN, &op, &opsz); errno_assert (rc == 0); nn_assert (opsz == sizeof (op)); nn_assert (op == AF_SP); opsz = sizeof (op); rc = nn_getsockopt (s, NN_SOL_SOCKET, NN_PROTOCOL, &op, &opsz); errno_assert (rc == 0); nn_assert (opsz == sizeof (op)); nn_assert (op == NN_PAIR); test_close (s); return 0; }
int testterm() { int rc; int s; struct nn_thread thread; printf("test term\n"); /* Close the socket with no associated endpoints. */ s = test_socket (AF_SP, NN_PAIR); test_close (s); /* Test nn_term() before nn_close(). */ nn_thread_init (&thread, worker, NULL); nn_sleep (100); nn_term(); /* Check that it's not possible to create new sockets after nn_term(). */ rc = nn_socket (AF_SP, NN_PAIR); nn_assert (rc == -1); errno_assert (nn_errno () == ETERM); /* Wait till worker thread terminates. */ nn_thread_term(&thread); printf("nn_thread_term finished\n"); return 0; }
DEF_TEST(document_tests, reporter) { test_empty(reporter); test_abort(reporter); test_abortWithFile(reporter); test_file(reporter); test_close(reporter); }
int main() { int err; Plfs_fd *fd = NULL; int open_flags = O_RDONLY | O_CREAT; /* Have thread 0 open the file first to ensure that it is created */ if (!MYTHREAD) { UPC_ADIO_Open( &fd, fn, open_flags, 0666, &err ); } upc_barrier; err = 0; /* Let the other threads open the file */ if (MYTHREAD) { UPC_ADIO_Open( &fd, fn, open_flags, 0666, &err ); } upc_barrier; assert (fd != NULL); test_close(fd, open_flags); pass(); }
void main(int argc, char *argv[]) { test_init(); int port = atoi(argv[1]); int sockfd = DI_init_measurer(port); char line[256]; sprintf(line, "(set_target %s)",argv[2]); DI_send_request(sockfd, line); test_start(sockfd); test_measurement(sockfd, "(measure (var \"a\"))", ME_measurement_create_string("45")); test_measurement(sockfd, "(measure (var \"b\"))", ME_measurement_create_string("2")); test_continue(sockfd); test_measurement(sockfd, "(measure (var \"a\"))", ME_measurement_create_string("46")); test_measurement(sockfd, "(measure (var \"b\"))", ME_measurement_create_string("2")); DI_send_request(sockfd, "(quit)"); close(sockfd); test_close(); }
int main () { #if !defined NN_HAVE_WINDOWS int sb; int i; int j; struct nn_thread threads [THREAD_COUNT]; /* Stress the shutdown algorithm. */ sb = test_socket (AF_SP, NN_PUB); test_bind (sb, SOCKET_ADDRESS); for (j = 0; j != 10; ++j) { for (i = 0; i != THREAD_COUNT; ++i) nn_thread_init (&threads [i], routine, NULL); for (i = 0; i != THREAD_COUNT; ++i) nn_thread_term (&threads [i]); } test_close (sb); #endif return 0; }
int main() { SDFileSystem sd(p11, p12, p13, p14, "sd"); FILE *f; char* str = TEST_STRING; char* buffer = (char*) malloc(sizeof(unsigned char)*strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); printf("Write files\n"); char filename[32]; for (int i=0; i<10; i++) { sprintf(filename, "/sd/test_%d.txt", i); printf("Creating file: %s\n", filename); f = test_open(filename, "w"); test_write(f, str); test_close(f); } printf("List files:\n"); DIR *d = opendir("/sd"); if (d == NULL) { printf("Error opening directory\n"); notify_completion(false); } struct dirent *p; while((p = readdir(d)) != NULL) { printf("%s\n", p->d_name); } closedir(d); notify_completion(true); }
int main (int argc, const char *argv[]) { int end0; int end1; struct nn_thread thread5; struct nn_thread thread6; int port = get_test_port(argc, argv); test_addr_from(socket_address_h, "tcp", "127.0.0.1", port); test_addr_from(socket_address_i, "tcp", "127.0.0.1", port + 1); test_addr_from(socket_address_j, "tcp", "127.0.0.1", port + 2); /* Test the bi-directional device with REQ/REP (headers). */ /* Start the devices. */ nn_thread_init (&thread5, device5, NULL); nn_thread_init (&thread6, device6, NULL); /* Create two sockets to connect to the device. */ end0 = test_socket (AF_SP, NN_REQ); test_connect (end0, socket_address_h); end1 = test_socket (AF_SP, NN_REP); test_connect (end1, socket_address_j); /* Wait for TCP to establish. */ nn_sleep (100); /* Pass a message between endpoints. */ test_send (end0, "XYZ"); test_recv (end1, "XYZ"); /* Now send a reply. */ test_send (end1, "REPLYXYZ"); test_recv (end0, "REPLYXYZ"); /* Clean up. */ test_close (end0); test_close (end1); /* Shut down the devices. */ nn_term (); nn_thread_term (&thread5); nn_thread_term (&thread6); return 0; }
int testipc_shutdown() { int sb; int i; int j; struct nn_thread threads [THREAD_COUNT]; printf("test ipc shutdown\n"); /* Stress the shutdown algorithm. */ #if defined(SIGPIPE) && defined(SIG_IGN) signal (SIGPIPE, SIG_IGN); #endif sb = test_socket (AF_SP, NN_PUB); test_bind (sb, SOCKET_ADDRESS); for (j = 0; j != TEST_LOOPS; ++j) { for (i = 0; i != THREAD_COUNT; ++i) nn_thread_init (&threads [i], routine, NULL); for (i = 0; i != THREAD_COUNT; ++i) nn_thread_term (&threads [i]); } test_close (sb); /* Test race condition of sending message while socket shutting down */ sb = test_socket (AF_SP, NN_PUSH); test_bind (sb, SOCKET_ADDRESS); for (j = 0; j != TEST_LOOPS; ++j) { for (i = 0; i != TEST2_THREAD_COUNT; ++i) nn_thread_init (&threads [i], routine2, NULL); active = TEST2_THREAD_COUNT; while ( active ) { (void) nn_send (sb, "hello", 5, NN_DONTWAIT); } for (i = 0; i != TEST2_THREAD_COUNT; ++i) nn_thread_term(&threads [i]); } test_close (sb); return 0; }
DEF_TEST(document_tests, reporter) { REQUIRE_PDF_DOCUMENT(document_tests, reporter); test_empty(reporter); test_abort(reporter); test_abortWithFile(reporter); test_file(reporter); test_close(reporter); }
/** @tested: open file, write file, read file, close_file */ void test_read_write() { // open a file and get fd int fd = test_open(first_doc); test_write_read(fd); int res = test_close(fd); assert(res == fd); test_std_rw(); }
int main () { int sb; int i; int j; struct nn_thread threads [THREAD_COUNT]; /* Stress the shutdown algorithm. */ sb = test_socket (AF_SP, NN_PUB); test_bind (sb, SOCKET_ADDRESS); for (j = 0; j != TEST_LOOPS; ++j) { for (i = 0; i != THREAD_COUNT; ++i) nn_thread_init (&threads [i], routine, NULL); for (i = 0; i != THREAD_COUNT; ++i) nn_thread_term (&threads [i]); } test_close (sb); /* Test race condition of sending message while socket shutting down */ sb = test_socket (AF_SP, NN_PUSH); test_bind (sb, SOCKET_ADDRESS); for (j = 0; j != TEST_LOOPS; ++j) { for (i = 0; i != TEST2_THREAD_COUNT; ++i) nn_thread_init (&threads [i], routine2, NULL); nn_atomic_init(&active, TEST2_THREAD_COUNT); while (active.n) { (void) nn_send (sb, "hello", 5, NN_DONTWAIT); } for (i = 0; i != TEST2_THREAD_COUNT; ++i) nn_thread_term (&threads [i]); nn_atomic_term(&active); } test_close (sb); return 0; }
int main() { #if defined(TARGET_KL25Z) SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); #elif defined(TARGET_nRF51822) //SDFileSystem sd(p20, p22, p25, p24, "sd"); SDFileSystem sd(p12, p13, p15, p14, "sd"); #elif defined(TARGET_NUCLEO_F030R8) || \ defined(TARGET_NUCLEO_F072RB) || \ defined(TARGET_NUCLEO_F091RC) || \ defined(TARGET_NUCLEO_F103RB) || \ defined(TARGET_NUCLEO_F302R8) || \ defined(TARGET_NUCLEO_F303RE) || \ defined(TARGET_NUCLEO_F334R8) || \ defined(TARGET_NUCLEO_F401RE) || \ defined(TARGET_NUCLEO_F411RE) || \ defined(TARGET_NUCLEO_L053R8) || \ defined(TARGET_NUCLEO_L152RE) SDFileSystem sd(D11, D12, D13, D10, "sd"); #elif defined(TARGET_LPC1768_MINI_DK2) SDFileSystem sd(SD_SDI, SD_SDO, SD_SCK, SD_CS, "sd"); #else SDFileSystem sd(p11, p12, p13, p14, "sd"); #endif led2 = 1; wait(0.5); FILE *f; char *str = TEST_STRING; char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); printf("Write files\n"); char filename[32]; for (int i = 0; i < 10; i++) { sprintf(filename, "/sd/test_%d.txt", i); printf("Creating file: %s\n", filename); f = test_open(filename, "w"); led2 = 0; test_write(f, str); test_close(f); } printf("List files:\n"); DIR *d = opendir("/sd"); if (d == NULL) { printf("Error opening directory\n"); notify_completion(false); } struct dirent *p; while ((p = readdir(d)) != NULL) printf("%s\n", p->d_name); closedir(d); notify_completion(true); }
void device6 (NN_UNUSED void *arg) { int rc; int dev2; int dev3; dev2 = test_socket (AF_SP_RAW, NN_REP); test_connect (dev2, socket_address_i); dev3 = test_socket (AF_SP_RAW, NN_REQ); test_bind (dev3, socket_address_j); /* Run the device. */ rc = nn_device (dev2, dev3); nn_assert (rc < 0 && nn_errno () == ETERM); /* Clean up. */ test_close (dev2); test_close (dev3); }
int main () { int rc; int sb; int sc; struct nn_iovec iov [2]; struct nn_msghdr hdr; char buf [6]; sb = test_socket (AF_SP, NN_PAIR); test_bind (sb, SOCKET_ADDRESS); sc = test_socket (AF_SP, NN_PAIR); test_connect (sc, SOCKET_ADDRESS); iov [0].iov_base = "AB"; iov [0].iov_len = 2; iov [1].iov_base = "CDEF"; iov [1].iov_len = 4; memset (&hdr, 0, sizeof (hdr)); hdr.msg_iov = iov; hdr.msg_iovlen = 2; rc = nn_sendmsg (sc, &hdr, 0); errno_assert (rc >= 0); nn_assert (rc == 6); iov [0].iov_base = buf; iov [0].iov_len = 4; iov [1].iov_base = buf + 4; iov [1].iov_len = 2; memset (&hdr, 0, sizeof (hdr)); hdr.msg_iov = iov; hdr.msg_iovlen = 2; rc = nn_recvmsg (sb, &hdr, 0); errno_assert (rc >= 0); nn_assert (rc == 6); nn_assert (memcmp (buf, "ABCDEF", 6) == 0); test_close (sc); test_close (sb); return 0; }
void device2 (NN_UNUSED void *arg) { int rc; int devc; int devd; /* Intialise the device sockets. */ devc = test_socket (AF_SP_RAW, NN_PULL); test_bind (devc, SOCKET_ADDRESS_C); devd = test_socket (AF_SP_RAW, NN_PUSH); test_bind (devd, SOCKET_ADDRESS_D); /* Run the device. */ rc = nn_device (devc, devd); nn_assert (rc < 0 && nn_errno () == ETERM); /* Clean up. */ test_close (devd); test_close (devc); }
void device1 (NN_UNUSED void *arg) { int rc; int deva; int devb; /* Intialise the device sockets. */ deva = test_socket (AF_SP_RAW, NN_PAIR); test_bind (deva, SOCKET_ADDRESS_A); devb = test_socket (AF_SP_RAW, NN_PAIR); test_bind (devb, SOCKET_ADDRESS_B); /* Run the device. */ rc = nn_device (deva, devb); nn_assert (rc < 0 && nn_errno () == ETERM); /* Clean up. */ test_close (devb); test_close (deva); }
static void routine (NN_UNUSED void *arg) { int s; s = nn_socket (AF_SP, NN_SUB); if (s < 0 && nn_errno () == EMFILE) return; errno_assert (s >= 0); test_connect (s, SOCKET_ADDRESS); test_close (s); }
/** @tested: open file, dup_file, dup2_file, close_file */ void test_open_close() { int dup_fd; int fd = test_open(first_doc); // fd should be 4 // 0 -- stdin, 1 -- stdout, 2 -- stderr, 3 -- cwd assert(fd == CWD + 1); dup_fd = set_fd_msg(fd, dup_file); assert(dup_fd == fd + 1); int res; res = test_dup2(fd, dup_fd + 1); assert(res == dup_fd + 1); // do some operations: read and write to file // close the duplicated file descriptor res = test_close(dup_fd); assert(res == dup_fd); res = test_close(dup_fd + 1); assert(res == dup_fd + 1); res = test_close(fd); assert(res == fd); }
void device5 (NN_UNUSED void *arg) { int rc; int dev0; int dev1; /* Intialise the device sockets. */ dev0 = test_socket (AF_SP_RAW, NN_REP); test_bind (dev0, socket_address_h); dev1 = test_socket (AF_SP_RAW, NN_REQ); test_bind (dev1, socket_address_i); /* Run the device. */ rc = nn_device (dev0, dev1); nn_assert (rc < 0 && nn_errno () == ETERM); /* Clean up. */ test_close (dev0); test_close (dev1); }
int main () { int end0; int end1; struct nn_thread thread5; struct nn_thread thread6; /* Test the bi-directional device with REQ/REP (headers). */ /* Start the devices. */ nn_thread_init (&thread5, device5, NULL); nn_thread_init (&thread6, device6, NULL); /* Create two sockets to connect to the device. */ end0 = test_socket (AF_SP, NN_REQ); test_connect (end0, SOCKET_ADDRESS_H); end1 = test_socket (AF_SP, NN_REP); test_connect (end1, SOCKET_ADDRESS_J); /* Wait for TCP to establish. */ nn_sleep (1000); /* Pass a message between endpoints. */ test_send (end0, "XYZ"); test_recv (end1, "XYZ"); /* Now send a reply. */ test_send (end1, "REPLYXYZ"); test_recv (end0, "REPLYXYZ"); /* Clean up. */ test_close (end0); test_close (end1); /* Shut down the devices. */ nn_term (); nn_thread_term (&thread5); nn_thread_term (&thread6); return 0; }
int main () { struct nn_thread thread; sb = test_socket (AF_SP, NN_PAIR); test_bind (sb, SOCKET_ADDRESS); sc = test_socket (AF_SP, NN_PAIR); test_connect (sc, SOCKET_ADDRESS); nn_thread_init (&thread, worker, NULL); test_recv (sb, "ABC"); test_recv (sb, "ABC"); nn_thread_term (&thread); test_close (sc); test_close (sb); return 0; }
/* test_text() verifies that we drop messages properly when sending invalid UTF-8, but not when we send valid data. */ void test_text () { int sb; int sc; int opt; uint8_t bad[20]; /* Negative testing... bad UTF-8 data for text. */ sb = test_socket (AF_SP, NN_PAIR); sc = test_socket (AF_SP, NN_PAIR); opt = NN_WS_MSG_TYPE_TEXT; test_setsockopt (sb, NN_WS, NN_WS_MSG_TYPE, &opt, sizeof (opt)); opt = NN_WS_MSG_TYPE_TEXT; test_setsockopt (sc, NN_WS, NN_WS_MSG_TYPE, &opt, sizeof (opt)); opt = 500; test_setsockopt (sb, NN_SOL_SOCKET, NN_RCVTIMEO, &opt, sizeof (opt)); test_bind (sb, socket_address); test_connect (sc, socket_address); test_send (sc, "GOOD"); test_recv (sb, "GOOD"); /* and the bad ... */ strcpy ((char *)bad, "BAD."); bad[2] = (char)0xDD; test_send (sc, (char *)bad); /* Make sure we dropped the frame. */ test_drop (sb, ETIMEDOUT); test_close (sb); test_close (sc); return; }
int main () { int rc; int push; int pull1; int pull2; int sndprio; pull1 = test_socket (AF_SP, NN_PULL); test_bind (pull1, SOCKET_ADDRESS_A); pull2 = test_socket (AF_SP, NN_PULL); test_bind (pull2, SOCKET_ADDRESS_B); push = test_socket (AF_SP, NN_PUSH); sndprio = 1; rc = nn_setsockopt (push, NN_SOL_SOCKET, NN_SNDPRIO, &sndprio, sizeof (sndprio)); errno_assert (rc == 0); test_connect (push, SOCKET_ADDRESS_A); sndprio = 2; rc = nn_setsockopt (push, NN_SOL_SOCKET, NN_SNDPRIO, &sndprio, sizeof (sndprio)); errno_assert (rc == 0); test_connect (push, SOCKET_ADDRESS_B); test_send (push, "ABC"); test_send (push, "DEF"); test_recv (pull1, "ABC"); test_recv (pull1, "DEF"); test_close (pull1); test_close (push); test_close (pull2); /* Test removing a pipe from the list. */ push = test_socket (AF_SP, NN_PUSH); test_bind (push, SOCKET_ADDRESS_A); pull1 = test_socket (AF_SP, NN_PULL); test_connect (pull1, SOCKET_ADDRESS_A); test_send (push, "ABC"); test_recv (pull1, "ABC"); test_close (pull1); rc = nn_send (push, "ABC", 3, NN_DONTWAIT); nn_assert (rc == -1 && nn_errno() == EAGAIN); pull1 = test_socket (AF_SP, NN_PULL); test_connect (pull1, SOCKET_ADDRESS_A); test_send (push, "ABC"); test_recv (pull1, "ABC"); test_close (pull1); test_close (push); return 0; }
void test_allocmsg_reqrep () { int rc; int req; void *p; struct nn_iovec iov; struct nn_msghdr hdr; /* Try to create an oversized message. */ p = nn_allocmsg (-1, 0); nn_assert (!p && nn_errno () == ENOMEM); p = nn_allocmsg (-1000, 0); nn_assert (!p && nn_errno () == ENOMEM); /* Try to create a message of unknown type. */ p = nn_allocmsg (100, 333); nn_assert (!p && nn_errno () == EINVAL); /* Create a socket. */ req = test_socket (AF_SP_RAW, NN_REQ); /* Make send fail and check whether the zero-copy buffer is left alone rather than deallocated. */ p = nn_allocmsg (100, 0); nn_assert (p); rc = nn_send (req, &p, NN_MSG, NN_DONTWAIT); nn_assert (rc < 0); errno_assert (nn_errno () == EAGAIN); memset (p, 0, 100); rc = nn_freemsg (p); errno_assert (rc == 0); /* Same thing with nn_sendmsg(). */ p = nn_allocmsg (100, 0); nn_assert (p); iov.iov_base = &p; iov.iov_len = NN_MSG; memset (&hdr, 0, sizeof (hdr)); hdr.msg_iov = &iov; hdr.msg_iovlen = 1; nn_sendmsg (req, &hdr, NN_DONTWAIT); errno_assert (nn_errno () == EAGAIN); memset (p, 0, 100); rc = nn_freemsg (p); errno_assert (rc == 0); /* Clean up. */ test_close (req); }
void device3 (NN_UNUSED void *arg) { int rc; int deve; /* Intialise the device socket. */ deve = test_socket (AF_SP_RAW, NN_BUS); test_bind (deve, SOCKET_ADDRESS_E); /* Run the device. */ rc = nn_device (deve, -1); nn_assert (rc < 0 && nn_errno () == ETERM); /* Clean up. */ test_close (deve); }