summaryrefslogtreecommitdiff
path: root/tests/context1.c
diff options
context:
space:
mode:
authorrpj <rpj>2000-01-04 10:19:28 +0000
committerrpj <rpj>2000-01-04 10:19:28 +0000
commita378d97dc9d9eadaef00a9f01816948db5f3a796 (patch)
tree654435cc0a85156c2a9b4793ab7d8e0da8424e32 /tests/context1.c
parent27d833666dfd72cc6e74c3900d3e8e66321bea3a (diff)
Main changes (see ChangeLog diff for details and attributions):-
- asynchronous cancellation added - attempt to hide internal exceptions from applications - kernel32 load/free problem fixed - new tests - changes only to comments in some tests
Diffstat (limited to 'tests/context1.c')
-rw-r--r--tests/context1.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/context1.c b/tests/context1.c
new file mode 100644
index 0000000..8f615e1
--- /dev/null
+++ b/tests/context1.c
@@ -0,0 +1,110 @@
+/*
+ * File: context1.c
+ *
+ * Test Synopsis: Test context switching method.
+ *
+ * Test Method (Validation or Falsification):
+ * -
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * -
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * - pthread_create
+ * pthread_exit
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+#include "../implement.h"
+
+static int washere = 0;
+
+static void * func(void * arg)
+{
+ washere = 1;
+
+ Sleep(1000);
+
+ return 0;
+}
+
+static void
+anotherEnding ()
+{
+ /*
+ * Switched context
+ */
+ washere++;
+
+ pthread_exit(0);
+}
+
+int
+main()
+{
+ pthread_t t;
+ HANDLE hThread;
+
+ assert(pthread_create(&t, NULL, func, NULL) == 0);
+
+ hThread = t->threadH;
+
+ Sleep(500);
+
+ SuspendThread(hThread);
+
+ if (WaitForSingleObject(hThread, 0) == WAIT_TIMEOUT)
+ {
+ /*
+ * Ok, thread did not exit before we got to it.
+ */
+ CONTEXT context;
+
+ context.ContextFlags = CONTEXT_CONTROL;
+
+ GetThreadContext(hThread, &context);
+ /*
+ *_x86 only!!!
+ */
+ context.Eip = (DWORD) anotherEnding;
+ SetThreadContext(hThread, &context);
+ ResumeThread(hThread);
+ }
+ else
+ {
+ printf("Exited early\n");
+ fflush(stdout);
+ }
+
+ Sleep(1000);
+
+ assert(washere == 2);
+
+ return 0;
+}
+