Skip to content
Browse files

Fix lines terminator

  • Loading branch information...
1 parent 6bb2c5f commit fa35c665eb1eb5e2c8b07913c3fe3fb3dddd9523 @Alexpux committed Oct 29, 2012
Showing with 368 additions and 368 deletions.
  1. +80 −80 README
  2. +1 −1 tests/dll1.cpp
  3. +1 −1 tests/dll_test1.cpp
  4. +15 −15 tests/dll_test2.cpp
  5. +14 −14 tests/lasterror_test1.cpp
  6. +1 −1 tests/lto_int.h
  7. +1 −1 tests/lto_test.cpp
  8. +1 −1 tests/omp_test.c
  9. +254 −254 tests/time_test.c
View
160 README
@@ -1,80 +1,80 @@
-The scripts provided by the MinGW-builds project[1][2] are designed
-for building the dual-target(i686/x86_64) MinGW compiler for i686/x86_64 hosts.
-
-The scripts are distributed under the 'BSD 3' license[3].
-
-In order to use the scripts provided by the MinGW-builds project it is needed:
-
-1. Windows-64bit or Linux + Wine-64bit
-
-2. Install MSYS:
- http://sourceforge.net/projects/mingwbuilds/files/external-binary-packages/
-
-3. Get the scripts into '<msys root>/home/<user>/mingw-builds':
- "cd && git clone git://github.com/niXman/mingw-builds.git"
-
-4. In the MSYS file structure delete the '/MinGW' directory.
-
-5. Delete the paths pointing to any preinstalled MinGW from the 'PATH'
- environment variable.
-
-6. Go into the MinGW-builds root directory.
- "cd && cd mingw-builds"
-
-7.
- The '--buildroot=<path>' option specifies to the script to use '<path>' as build directory.
- By default used MSYS user home directory.
- The '--preload' option specifies to the script to pre-download all the sources
- and only after that, to begin the building. This allows to build different
- versions of GCC simultaneously.
- The '--download' option specifies to the script to download only the sources.
- The '--dwarf' option specifies to the script to use DWARF exeptions handling
- instead of SJLJ. This allows building for i686 host only, and i686 target only.
- The '--use-lto' option specifies to the script to build with using LTO.
- The '--no-strip' option specifies to the script to install without striping.
- The '--no-multilib' option specifies to the script to build without multilib support.
- The '--dyn-deps' option specifies to the script to build GCC with dynamically dependencies.
- The '--rev=N' option specifies to the script the number of the build revision.
- The '--threads=model' option specifies to the script the used threads model.
- For more options please run: "./build --help"
-
-8. Run:
- "./build gcc-4.6.3 x32" for building i686-MinGW
- "./build gcc-4.6.3 x64" for building x86_64-MinGW
- "./build gcc-4.6.3 x32 x64" for building i686-MinGW and x86_64-MinGW
- "./build gcc-4.6.3 --preload x32 x64" for building i686-MinGW and x86_64-MinGW
- "./build gcc-4.6.3 --dwarf" for building i686-MinGW with DWARF exception handling
-
-For example, during the process of building of the i686-gcc-4.6.3 will
- be created the following directories:
- /mingw-gcc-4.6.3-build-x32
- /mingw-gcc-4.6.3-libs-x32
- /mingw-gcc-4.6.3-logs-x32
- /mingw-gcc-4.6.3-x32
-
-For x86_64:
- /mingw-gcc-4.6.3-build-x64
- /mingw-gcc-4.6.3-libs-x64
- /mingw-gcc-4.6.3-logs-x64
- /mingw-gcc-4.6.3-x64
-
-And the sources directory:
- /mingw-src
-
-
-
-The archives with the built MinGW will be created in '<msys root>/home/<user>/'
-
-At the moment, successfully building the following versions:
- gcc-4.6.2
- gcc-4.6.3
- gcc-4.7.0
- gcc-4.7.1
- gcc-4.7.2
- gcc-4_6-branch (currently 4.6.4 prerelease)
- gcc-4_7-branch (currently 4.7.3 prerelease)
- gcc-trunk (currently 4.8.0 snapshot)
-
-[1] http://code.google.com/p/mingw-builds/
-[2] http://sourceforge.net/projects/mingwbuilds/
-[3] http://www.opensource.org/licenses/BSD-3-Clause
+The scripts provided by the MinGW-builds project[1][2] are designed
+for building the dual-target(i686/x86_64) MinGW compiler for i686/x86_64 hosts.
+
+The scripts are distributed under the 'BSD 3' license[3].
+
+In order to use the scripts provided by the MinGW-builds project it is needed:
+
+1. Windows-64bit or Linux + Wine-64bit
+
+2. Install MSYS:
+ http://sourceforge.net/projects/mingwbuilds/files/external-binary-packages/
+
+3. Get the scripts into '<msys root>/home/<user>/mingw-builds':
+ "cd && git clone git://github.com/niXman/mingw-builds.git"
+
+4. In the MSYS file structure delete the '/MinGW' directory.
+
+5. Delete the paths pointing to any preinstalled MinGW from the 'PATH'
+ environment variable.
+
+6. Go into the MinGW-builds root directory.
+ "cd && cd mingw-builds"
+
+7.
+ The '--buildroot=<path>' option specifies to the script to use '<path>' as build directory.
+ By default used MSYS user home directory.
+ The '--preload' option specifies to the script to pre-download all the sources
+ and only after that, to begin the building. This allows to build different
+ versions of GCC simultaneously.
+ The '--download' option specifies to the script to download only the sources.
+ The '--dwarf' option specifies to the script to use DWARF exeptions handling
+ instead of SJLJ. This allows building for i686 host only, and i686 target only.
+ The '--use-lto' option specifies to the script to build with using LTO.
+ The '--no-strip' option specifies to the script to install without striping.
+ The '--no-multilib' option specifies to the script to build without multilib support.
+ The '--dyn-deps' option specifies to the script to build GCC with dynamically dependencies.
+ The '--rev=N' option specifies to the script the number of the build revision.
+ The '--threads=model' option specifies to the script the used threads model.
+ For more options please run: "./build --help"
+
+8. Run:
+ "./build gcc-4.6.3 x32" for building i686-MinGW
+ "./build gcc-4.6.3 x64" for building x86_64-MinGW
+ "./build gcc-4.6.3 x32 x64" for building i686-MinGW and x86_64-MinGW
+ "./build gcc-4.6.3 --preload x32 x64" for building i686-MinGW and x86_64-MinGW
+ "./build gcc-4.6.3 --dwarf" for building i686-MinGW with DWARF exception handling
+
+For example, during the process of building of the i686-gcc-4.6.3 will
+ be created the following directories:
+ /mingw-gcc-4.6.3-build-x32
+ /mingw-gcc-4.6.3-libs-x32
+ /mingw-gcc-4.6.3-logs-x32
+ /mingw-gcc-4.6.3-x32
+
+For x86_64:
+ /mingw-gcc-4.6.3-build-x64
+ /mingw-gcc-4.6.3-libs-x64
+ /mingw-gcc-4.6.3-logs-x64
+ /mingw-gcc-4.6.3-x64
+
+And the sources directory:
+ /mingw-src
+
+
+
+The archives with the built MinGW will be created in '<msys root>/home/<user>/'
+
+At the moment, successfully building the following versions:
+ gcc-4.6.2
+ gcc-4.6.3
+ gcc-4.7.0
+ gcc-4.7.1
+ gcc-4.7.2
+ gcc-4_6-branch (currently 4.6.4 prerelease)
+ gcc-4_7-branch (currently 4.7.3 prerelease)
+ gcc-trunk (currently 4.8.0 snapshot)
+
+[1] http://code.google.com/p/mingw-builds/
+[2] http://sourceforge.net/projects/mingwbuilds/
+[3] http://www.opensource.org/licenses/BSD-3-Clause
View
2 tests/dll1.cpp
@@ -1,4 +1,4 @@
-
+
#include <cstdio>
extern "C" void func() {
View
2 tests/dll_test1.cpp
@@ -1,4 +1,4 @@
-
+
#include <windows.h>
#include <cstdio>
View
30 tests/dll_test2.cpp
@@ -1,15 +1,15 @@
-
-#include <stdio.h>
-
-void f();
-
-int main(int, char **)
-{
- try {
- f();
- return 1;
- } catch(int) {
- return 0;
- }
- return 1;
-}
+
+#include <stdio.h>
+
+void f();
+
+int main(int, char **)
+{
+ try {
+ f();
+ return 1;
+ } catch(int) {
+ return 0;
+ }
+ return 1;
+}
View
28 tests/lasterror_test1.cpp
@@ -1,14 +1,14 @@
-#include <windows.h>
-
-struct C { ~C() {} };
-
-int Test() {
- C t;
- return ::GetLastError();
-}
-
-int main(int, const char**) {
- ::SetLastError(2);
-
- return Test()-2;
-}
+#include <windows.h>
+
+struct C { ~C() {} };
+
+int Test() {
+ C t;
+ return ::GetLastError();
+}
+
+int main(int, const char**) {
+ ::SetLastError(2);
+
+ return Test()-2;
+}
View
2 tests/lto_int.h
@@ -1,4 +1,4 @@
-class Int
+class Int
{
public:
Int(int i = 0);
View
2 tests/lto_test.cpp
@@ -1,4 +1,4 @@
-#include <iostream>
+#include <iostream>
#include <time.h>
#include "lto_int.h"
View
2 tests/omp_test.c
@@ -1,4 +1,4 @@
-# include <stdlib.h>
+# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# include <omp.h>
View
508 tests/time_test.c
@@ -1,254 +1,254 @@
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <errno.h>
-#include <windows.h>
-
-#define POW10_3 1000
-#define POW10_6 1000000
-#define POW10_9 1000000000
-
-#define assert(_Expression) (void)( (!!(_Expression)) || (_my_assert(#_Expression, __FILE__, __LINE__), 0) )
-
-static __inline void _my_assert(char *message, char *file, unsigned int line)
-{
- fprintf(stderr, "Assertion failed: %s , file %s, line %u\n", message, file, line);
- exit(1);
-}
-
-void test_clock_gettime()
-{
- int rc;
- struct timespec tp, request = { 1, 0 }, remain;
-
- rc = clock_gettime(CLOCK_REALTIME, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
- rc = clock_gettime(CLOCK_MONOTONIC, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_MONOTONIC)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
- rc = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_PROCESS_CPUTIME_ID)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
- rc = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_THREAD_CPUTIME_ID)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
- rc = clock_nanosleep(CLOCK_REALTIME, 0, &request, &remain);
- assert(rc == 0);
-
- rc = clock_gettime(CLOCK_REALTIME, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
- rc = clock_gettime(CLOCK_MONOTONIC, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_MONOTONIC)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
- rc = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_PROCESS_CPUTIME_ID)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
- rc = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_THREAD_CPUTIME_ID)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
-}
-
-double sub_and_div(const struct timespec *t1, const struct timespec *t2, const struct timespec *r)
-{
- __int64 diff = (t2->tv_sec - t1->tv_sec) * POW10_9 + (t2->tv_nsec - t1->tv_nsec);
- return diff / (double) (r->tv_sec * POW10_9 + r->tv_nsec);
-}
-
-void test_clock_getres(char *name, int id)
-{
- int rc;
- double d;
- struct timespec tp, t1, t2;
-
- rc = clock_getres(id, &tp);
- assert(rc == 0);
- printf("%s resolution: %d.%09d sec\n", name, (int) tp.tv_sec, (int) tp.tv_nsec);
-
- rc = clock_gettime(id, &t1);
- assert(rc == 0);
- printf("%s time: %d.%09d sec\n", name, (int) t1.tv_sec, (int) t1.tv_nsec);
-
- if (id == CLOCK_REALTIME || id == CLOCK_MONOTONIC) {
- struct timespec request = {1, 0};
- clock_nanosleep(CLOCK_REALTIME, 0, &request, NULL);
- } else {
- long i;
- for (i = 0; i < 100000000; i++) {
- rand();
- }
- }
-
- rc = clock_gettime(id, &t2);
- assert(rc == 0);
- printf("%s time: %d.%09d sec\n", name, (int) t2.tv_sec, (int) t2.tv_nsec);
-
- d = sub_and_div(&t1, &t2, &tp);
- printf("sub_and_div: %7.3lf\n", d);
- printf("\n");
-}
-
-void test_clock_settime()
-{
- int rc;
- struct timespec tp, request = { 1, 0 }, remain;
-
- rc = clock_gettime(CLOCK_REALTIME, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
- rc = clock_settime(CLOCK_MONOTONIC, &tp);
- assert(rc == -1 && (errno == EINVAL));
-
- rc = clock_settime(CLOCK_PROCESS_CPUTIME_ID, &tp);
- assert(rc == -1 && (errno == EINVAL));
-
- rc = clock_settime(CLOCK_THREAD_CPUTIME_ID, &tp);
- assert(rc == -1 && (errno == EINVAL));
-
- rc = clock_settime(CLOCK_REALTIME, &tp);
- assert(rc == 0 || (errno == EPERM));
-
- rc = clock_gettime(CLOCK_REALTIME, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-}
-
-void test_clock_nanosleep()
-{
- int rc;
- struct timespec tp, request = { 1, 0 }, remain;
-
- rc = clock_nanosleep(CLOCK_MONOTONIC, 0, &request, &remain);
- assert(rc == -1 && errno == EINVAL);
-
- rc = clock_nanosleep(CLOCK_PROCESS_CPUTIME_ID, 0, &request, &remain);
- assert(rc == -1 && errno == EINVAL);
-
- rc = clock_nanosleep(CLOCK_THREAD_CPUTIME_ID, 0, &request, &remain);
- assert(rc == -1 && errno == EINVAL);
-
- rc = clock_gettime(CLOCK_REALTIME, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
- rc = clock_nanosleep(CLOCK_REALTIME, 0, &request, &remain);
- assert(rc == 0);
-
- rc = clock_gettime(CLOCK_REALTIME, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-
- request.tv_sec = tp.tv_sec + 1;
- request.tv_nsec = 0;
-
- rc = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &request, &remain);
- assert(rc == 0);
-
- rc = clock_gettime(CLOCK_REALTIME, &tp);
- assert(rc == 0);
- printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
-}
-
-extern int __cdecl getntptimeofday(struct timespec *tp, struct timezone *tz);
-
-__int64 timespec_diff_as_ms(struct timespec *__old, struct timespec *__new)
-{
- return (__new->tv_sec - __old->tv_sec) * POW10_3
- + (__new->tv_nsec - __old->tv_nsec) / POW10_6;
-}
-
-unsigned __stdcall start_address(void *dummy)
-{
- int counter = 0;
- struct timespec request = { 1, 0 }, remain;
-
- while (counter < 5) {
- int rc = nanosleep(&request, &remain);
- if (rc != 0) {
- printf("nanosleep interrupted, remain %d.%09d sec.\n",
- (int) remain.tv_sec, (int) remain.tv_nsec);
- } else {
- printf("nanosleep succeeded.\n");
- }
-
- counter ++;
- }
-
- return 0;
-}
-
-void WINAPI usr_apc(ULONG_PTR dwParam)
-{
- long *index = (long *) dwParam;
- printf("running apc %ld\n", *index);
-}
-
-void test_apc()
-{
- long i, rc, data[5];
- HANDLE thread;
-
- thread = (HANDLE) _beginthreadex(NULL, 0, start_address, NULL, 0, NULL);
- if (thread == NULL) {
- exit(1);
- }
-
- for (i = 0; i < 5; i++) {
- data[i] = i;
- Sleep(250 + rand() % 250);
- rc = QueueUserAPC(usr_apc, thread, (ULONG_PTR) & data[i]);
- if (rc == 0) {
- printf("QueueUserAPC failed: %ld\n", GetLastError());
- exit(1);
- }
- }
-
- rc = WaitForSingleObject(thread, INFINITE);
- if (rc != WAIT_OBJECT_0) {
- printf("WaitForSingleObject failed with %ld: %ld\n", rc, GetLastError());
- exit(1);
- }
-}
-
-int main() {
- int rc;
- struct timespec tp, tp2, request = { 1, 0 }, remain;
-
- test_clock_gettime();
-
- test_clock_getres(" CLOCK_REALTIME", CLOCK_REALTIME);
- test_clock_getres(" CLOCK_MONOTONIC", CLOCK_MONOTONIC);
- test_clock_getres("CLOCK_PROCESS_CPUTIME_ID", CLOCK_PROCESS_CPUTIME_ID);
- test_clock_getres(" CLOCK_THREAD_CPUTIME_ID", CLOCK_THREAD_CPUTIME_ID);
-
- test_clock_settime();
-
- test_clock_nanosleep();
-
- getntptimeofday(&tp, NULL);
- rc = nanosleep(&request, &remain);
- getntptimeofday(&tp2, NULL);
-
- if (rc != 0) {
- printf("remain: %d.%09d\n", (int) remain.tv_sec, (int) remain.tv_nsec);
- }
-
- printf("%d.%09d\n", (int) tp.tv_sec, (int) tp.tv_nsec);
- printf("%d.%09d\n", (int) tp2.tv_sec, (int) tp2.tv_nsec);
- printf("sleep %d ms\n\n", (int) timespec_diff_as_ms(&tp, &tp2));
-
- test_apc();
-
- return 0;
-}
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <errno.h>
+#include <windows.h>
+
+#define POW10_3 1000
+#define POW10_6 1000000
+#define POW10_9 1000000000
+
+#define assert(_Expression) (void)( (!!(_Expression)) || (_my_assert(#_Expression, __FILE__, __LINE__), 0) )
+
+static __inline void _my_assert(char *message, char *file, unsigned int line)
+{
+ fprintf(stderr, "Assertion failed: %s , file %s, line %u\n", message, file, line);
+ exit(1);
+}
+
+void test_clock_gettime()
+{
+ int rc;
+ struct timespec tp, request = { 1, 0 }, remain;
+
+ rc = clock_gettime(CLOCK_REALTIME, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+ rc = clock_gettime(CLOCK_MONOTONIC, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_MONOTONIC)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+ rc = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_PROCESS_CPUTIME_ID)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+ rc = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_THREAD_CPUTIME_ID)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+ rc = clock_nanosleep(CLOCK_REALTIME, 0, &request, &remain);
+ assert(rc == 0);
+
+ rc = clock_gettime(CLOCK_REALTIME, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+ rc = clock_gettime(CLOCK_MONOTONIC, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_MONOTONIC)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+ rc = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_PROCESS_CPUTIME_ID)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+ rc = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_THREAD_CPUTIME_ID)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+}
+
+double sub_and_div(const struct timespec *t1, const struct timespec *t2, const struct timespec *r)
+{
+ __int64 diff = (t2->tv_sec - t1->tv_sec) * POW10_9 + (t2->tv_nsec - t1->tv_nsec);
+ return diff / (double) (r->tv_sec * POW10_9 + r->tv_nsec);
+}
+
+void test_clock_getres(char *name, int id)
+{
+ int rc;
+ double d;
+ struct timespec tp, t1, t2;
+
+ rc = clock_getres(id, &tp);
+ assert(rc == 0);
+ printf("%s resolution: %d.%09d sec\n", name, (int) tp.tv_sec, (int) tp.tv_nsec);
+
+ rc = clock_gettime(id, &t1);
+ assert(rc == 0);
+ printf("%s time: %d.%09d sec\n", name, (int) t1.tv_sec, (int) t1.tv_nsec);
+
+ if (id == CLOCK_REALTIME || id == CLOCK_MONOTONIC) {
+ struct timespec request = {1, 0};
+ clock_nanosleep(CLOCK_REALTIME, 0, &request, NULL);
+ } else {
+ long i;
+ for (i = 0; i < 100000000; i++) {
+ rand();
+ }
+ }
+
+ rc = clock_gettime(id, &t2);
+ assert(rc == 0);
+ printf("%s time: %d.%09d sec\n", name, (int) t2.tv_sec, (int) t2.tv_nsec);
+
+ d = sub_and_div(&t1, &t2, &tp);
+ printf("sub_and_div: %7.3lf\n", d);
+ printf("\n");
+}
+
+void test_clock_settime()
+{
+ int rc;
+ struct timespec tp, request = { 1, 0 }, remain;
+
+ rc = clock_gettime(CLOCK_REALTIME, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+ rc = clock_settime(CLOCK_MONOTONIC, &tp);
+ assert(rc == -1 && (errno == EINVAL));
+
+ rc = clock_settime(CLOCK_PROCESS_CPUTIME_ID, &tp);
+ assert(rc == -1 && (errno == EINVAL));
+
+ rc = clock_settime(CLOCK_THREAD_CPUTIME_ID, &tp);
+ assert(rc == -1 && (errno == EINVAL));
+
+ rc = clock_settime(CLOCK_REALTIME, &tp);
+ assert(rc == 0 || (errno == EPERM));
+
+ rc = clock_gettime(CLOCK_REALTIME, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+}
+
+void test_clock_nanosleep()
+{
+ int rc;
+ struct timespec tp, request = { 1, 0 }, remain;
+
+ rc = clock_nanosleep(CLOCK_MONOTONIC, 0, &request, &remain);
+ assert(rc == -1 && errno == EINVAL);
+
+ rc = clock_nanosleep(CLOCK_PROCESS_CPUTIME_ID, 0, &request, &remain);
+ assert(rc == -1 && errno == EINVAL);
+
+ rc = clock_nanosleep(CLOCK_THREAD_CPUTIME_ID, 0, &request, &remain);
+ assert(rc == -1 && errno == EINVAL);
+
+ rc = clock_gettime(CLOCK_REALTIME, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+ rc = clock_nanosleep(CLOCK_REALTIME, 0, &request, &remain);
+ assert(rc == 0);
+
+ rc = clock_gettime(CLOCK_REALTIME, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+
+ request.tv_sec = tp.tv_sec + 1;
+ request.tv_nsec = 0;
+
+ rc = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &request, &remain);
+ assert(rc == 0);
+
+ rc = clock_gettime(CLOCK_REALTIME, &tp);
+ assert(rc == 0);
+ printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
+}
+
+extern int __cdecl getntptimeofday(struct timespec *tp, struct timezone *tz);
+
+__int64 timespec_diff_as_ms(struct timespec *__old, struct timespec *__new)
+{
+ return (__new->tv_sec - __old->tv_sec) * POW10_3
+ + (__new->tv_nsec - __old->tv_nsec) / POW10_6;
+}
+
+unsigned __stdcall start_address(void *dummy)
+{
+ int counter = 0;
+ struct timespec request = { 1, 0 }, remain;
+
+ while (counter < 5) {
+ int rc = nanosleep(&request, &remain);
+ if (rc != 0) {
+ printf("nanosleep interrupted, remain %d.%09d sec.\n",
+ (int) remain.tv_sec, (int) remain.tv_nsec);
+ } else {
+ printf("nanosleep succeeded.\n");
+ }
+
+ counter ++;
+ }
+
+ return 0;
+}
+
+void WINAPI usr_apc(ULONG_PTR dwParam)
+{
+ long *index = (long *) dwParam;
+ printf("running apc %ld\n", *index);
+}
+
+void test_apc()
+{
+ long i, rc, data[5];
+ HANDLE thread;
+
+ thread = (HANDLE) _beginthreadex(NULL, 0, start_address, NULL, 0, NULL);
+ if (thread == NULL) {
+ exit(1);
+ }
+
+ for (i = 0; i < 5; i++) {
+ data[i] = i;
+ Sleep(250 + rand() % 250);
+ rc = QueueUserAPC(usr_apc, thread, (ULONG_PTR) & data[i]);
+ if (rc == 0) {
+ printf("QueueUserAPC failed: %ld\n", GetLastError());
+ exit(1);
+ }
+ }
+
+ rc = WaitForSingleObject(thread, INFINITE);
+ if (rc != WAIT_OBJECT_0) {
+ printf("WaitForSingleObject failed with %ld: %ld\n", rc, GetLastError());
+ exit(1);
+ }
+}
+
+int main() {
+ int rc;
+ struct timespec tp, tp2, request = { 1, 0 }, remain;
+
+ test_clock_gettime();
+
+ test_clock_getres(" CLOCK_REALTIME", CLOCK_REALTIME);
+ test_clock_getres(" CLOCK_MONOTONIC", CLOCK_MONOTONIC);
+ test_clock_getres("CLOCK_PROCESS_CPUTIME_ID", CLOCK_PROCESS_CPUTIME_ID);
+ test_clock_getres(" CLOCK_THREAD_CPUTIME_ID", CLOCK_THREAD_CPUTIME_ID);
+
+ test_clock_settime();
+
+ test_clock_nanosleep();
+
+ getntptimeofday(&tp, NULL);
+ rc = nanosleep(&request, &remain);
+ getntptimeofday(&tp2, NULL);
+
+ if (rc != 0) {
+ printf("remain: %d.%09d\n", (int) remain.tv_sec, (int) remain.tv_nsec);
+ }
+
+ printf("%d.%09d\n", (int) tp.tv_sec, (int) tp.tv_nsec);
+ printf("%d.%09d\n", (int) tp2.tv_sec, (int) tp2.tv_nsec);
+ printf("sleep %d ms\n\n", (int) timespec_diff_as_ms(&tp, &tp2));
+
+ test_apc();
+
+ return 0;
+}

0 comments on commit fa35c66

Please sign in to comment.
Something went wrong with that request. Please try again.