1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/*
* Copyright 2010 The Native Client Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/*
* Test for getpid syscall.
*/
#ifdef USE_RAW_SYSCALLS
#include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h"
#endif
#include "native_client/tests/syscalls/test.h" //NOLINT
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef USE_RAW_SYSCALLS
#define GETPID NACL_SYSCALL(getpid)
#else
#define GETPID getpid
#endif
bool TestGetPid() {
bool test_status;
const char *testname = "getpid_test";
pid_t pid_one = GETPID();
pid_t pid_two = GETPID();
// check if it's greater than 0.
if ((pid_one > 0) && (pid_one == pid_two)) {
test_status =
test::Passed(testname,
"getpid returned what appears to be a valid pid.");
} else if (pid_one == pid_two) {
// a buffer size that should be sufficient
char buffer[256];
snprintf(buffer,
255,
"getpid returned an invalid pid for this test: %d",
pid_one);
buffer[255] = 0;
test_status = test::Failed(testname, buffer, __FILE__, __LINE__);
} else {
char buffer[256];
snprintf(buffer,
255,
"getpid returned different pids for the same process. First "
"time it was called: %d Second time: %d",
pid_one,
pid_two);
buffer[255] = 0;
test_status = test::Failed(testname, buffer, __FILE__, __LINE__);
}
return test_status;
}
/*
* function testSuite()
*
* Run through a complete sequence of file tests.
*
* returns true if all tests succeed. false if one or more fail.
*/
bool TestSuite() {
bool ret = true;
ret &= TestGetPid();
return ret;
}
/*
* Main entry point.
*
* Runs all tests and calls system exit with appropriate value
* 0 - success, all tests passed.
* -1 - one or more tests failed.
*/
int main(const int argc, const char *argv[]) {
bool passed;
// run the full test suite
passed = TestSuite();
if (passed) {
printf("All tests PASSED\n");
exit(0);
} else {
printf("One or more tests FAILED\n");
exit(-1);
}
}
|