summaryrefslogtreecommitdiff
path: root/nsprpub/pr/tests/fdcach.c
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/tests/fdcach.c')
-rw-r--r--nsprpub/pr/tests/fdcach.c106
1 files changed, 104 insertions, 2 deletions
diff --git a/nsprpub/pr/tests/fdcach.c b/nsprpub/pr/tests/fdcach.c
index 5fa51b706a..2fb2e5b810 100644
--- a/nsprpub/pr/tests/fdcach.c
+++ b/nsprpub/pr/tests/fdcach.c
@@ -6,7 +6,7 @@
/*
* File: fdcach.c
* Description:
- * This test verifies that the fd cache is working
+ * This test verifies that the fd cache and stack are working
* correctly.
*/
@@ -18,7 +18,7 @@
/*
* Define ORDER_PRESERVED if the implementation of PR_SetFDCacheSize
* preserves the ordering of the fd's when moving them between the
- * cache.
+ * cache and the stack.
*/
#define ORDER_PRESERVED 1
@@ -35,6 +35,12 @@ int main(int argc, char **argv)
PRFileDesc *savefds[NUM_FDS];
int numfds = sizeof(fds)/sizeof(fds[0]);
+ /*
+ * Switch between cache and stack when they are empty.
+ * Then start with the fd cache.
+ */
+ PR_SetFDCacheSize(0, FD_CACHE_SIZE);
+ PR_SetFDCacheSize(0, 0);
PR_SetFDCacheSize(0, FD_CACHE_SIZE);
/* Add some fd's to the fd cache. */
@@ -76,6 +82,59 @@ int main(int argc, char **argv)
}
}
+ /* Switch to the fd stack. */
+ PR_SetFDCacheSize(0, 0);
+
+ /*
+ * Create some fd's. These fd's should come from
+ * the fd stack.
+ */
+ for (i = 0; i < numfds; i++) {
+ fds[i] = PR_NewTCPSocket();
+ if (NULL == fds[i]) {
+ fprintf(stderr, "PR_NewTCPSocket failed\n");
+ exit(1);
+ }
+#ifdef ORDER_PRESERVED
+ if (fds[i] != savefds[numfds-1-i]) {
+ fprintf(stderr, "fd stack malfunctioned\n");
+ exit(1);
+ }
+#else
+ savefds[numfds-1-i] = fds[i];
+#endif
+ }
+ /* Put the fd's back to the fd stack. */
+ for (i = 0; i < numfds; i++) {
+ if (PR_Close(savefds[i]) == PR_FAILURE) {
+ fprintf(stderr, "PR_Close failed\n");
+ exit(1);
+ }
+ }
+
+ /*
+ * Now create some fd's and verify the LIFO ordering of
+ * the fd stack.
+ */
+ for (i = 0; i < numfds; i++) {
+ fds[i] = PR_NewTCPSocket();
+ if (NULL == fds[i]) {
+ fprintf(stderr, "PR_NewTCPSocket failed\n");
+ exit(1);
+ }
+ if (fds[i] != savefds[numfds-1-i]) {
+ fprintf(stderr, "fd stack malfunctioned\n");
+ exit(1);
+ }
+ }
+ /* Put the fd's back to the fd stack. */
+ for (i = 0; i < numfds; i++) {
+ if (PR_Close(savefds[i]) == PR_FAILURE) {
+ fprintf(stderr, "PR_Close failed\n");
+ exit(1);
+ }
+ }
+
/* Switch to the fd cache. */
PR_SetFDCacheSize(0, FD_CACHE_SIZE);
@@ -119,6 +178,49 @@ int main(int argc, char **argv)
}
}
+ /* Switch to the fd stack. */
+ PR_SetFDCacheSize(0, 0);
+
+ for (i = 0; i < numfds; i++) {
+ fds[i] = PR_NewTCPSocket();
+ if (NULL == fds[i]) {
+ fprintf(stderr, "PR_NewTCPSocket failed\n");
+ exit(1);
+ }
+#ifdef ORDER_PRESERVED
+ if (fds[i] != savefds[numfds-1-i]) {
+ fprintf(stderr, "fd stack malfunctioned\n");
+ exit(1);
+ }
+#else
+ savefds[numfds-1-i];
+#endif
+ }
+ for (i = 0; i < numfds; i++) {
+ if (PR_Close(savefds[i]) == PR_FAILURE) {
+ fprintf(stderr, "PR_Close failed\n");
+ exit(1);
+ }
+ }
+
+ for (i = 0; i < numfds; i++) {
+ fds[i] = PR_NewTCPSocket();
+ if (NULL == fds[i]) {
+ fprintf(stderr, "PR_NewTCPSocket failed\n");
+ exit(1);
+ }
+ if (fds[i] != savefds[numfds-1-i]) {
+ fprintf(stderr, "fd stack malfunctioned\n");
+ exit(1);
+ }
+ }
+ for (i = 0; i < numfds; i++) {
+ if (PR_Close(savefds[i]) == PR_FAILURE) {
+ fprintf(stderr, "PR_Close failed\n");
+ exit(1);
+ }
+ }
+
PR_Cleanup();
printf("PASS\n");
return 0;