Mercurial > trustbridge
annotate common/selftest.c @ 734:f6796ff72b65
Only show overlay if it is not "0"
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 03 Jul 2014 16:28:35 +0200 |
parents | 80d1a80b3e8d |
children | f89b41fa7048 |
rev | line source |
---|---|
634
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 #include "selftest.h" |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 #include "binverify.h" |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 #include "strhelp.h" |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 #include "logging.h" |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 bool |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 selftest() |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 { |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #ifdef WIN32 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 wchar_t wPath[MAX_PATH]; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 char *utf8path = NULL; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1)) |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 { |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 PRINTLASTERROR ("Failed to obtain module file name. Path too long?"); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 return false; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 } |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 /* wPath might not be 0 terminated */ |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 wPath[MAX_PATH - 1] = '\0'; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 utf8path = wchar_to_utf8 (wPath, wcsnlen(wPath, MAX_PATH)); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 if (utf8path == NULL) |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 { |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 ERRORPRINTF ("Failed to convert module path to utf-8"); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 return false; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 } |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 if (!verify_binary (utf8path, strlen(utf8path)) != VerifyValid) |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 { |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 ERRORPRINTF ("Verification of the binary failed"); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 syslog_error_printf ("Integrity check failed."); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 xfree(utf8path); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 return false; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 } |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 xfree(utf8path); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 #else |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 if (!verify_binary ("/proc/self/exe", 14) != VerifyValid) |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 { |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 syslog_error_printf ("Integrity check failed."); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 return false; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 } |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 #endif |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 } |