int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int incr; /* increment */ long nbrkpt; /* new brk point value */ long cur_brk_val; /* current size returned by sbrk */ long aft_brk_val; /* current size returned by sbrk */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); /* * Attempt to control how fast we get to test max size. * Every MAX_SIZE_LC'th lc will be fastest test will reach max size. */ incr = (Max_brk_byte_size - Beg_brk_val) / (MAX_SIZE_LC / 2); if ((incr * 2) < 4096) /* make sure that process will grow */ incr += 4096 / 2; for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* * Determine new value to give brk * Every even lc value, grow by 2 incr and * every odd lc value, strink by one incr. * If lc is equal to 3, no change, special case. */ cur_brk_val = (long)sbrk(0); if (lc == 3) { nbrkpt = cur_brk_val; /* no change, special one time case */ } else if ((lc % 2) == 0) { /* * grow */ nbrkpt = cur_brk_val + (2 * incr); if (nbrkpt > Max_brk_byte_size) nbrkpt = Beg_brk_val; /* start over */ } else { /* * shrink */ nbrkpt = cur_brk_val - incr; } /**** printf("cur_brk_val = %d, nbrkpt = %d, incr = %d, lc = %d\n", cur_brk_val, nbrkpt, incr, lc); ****/ /* * Call brk(2) */ TEST(brk((char *)nbrkpt)); /* check return code */ if (TEST_RETURN == -1) { aft_brk_val = (long)sbrk(0); tst_resm(TFAIL|TTERRNO, "brk(%ld) failed (size before %ld, after %ld)", nbrkpt, cur_brk_val, aft_brk_val); } else { if (STD_FUNCTIONAL_TEST) { aft_brk_val = (long)sbrk(0); if (aft_brk_val == nbrkpt) { tst_resm(TPASS, "brk(%ld) returned %ld, new size verified by sbrk", nbrkpt, TEST_RETURN); } else { tst_resm(TFAIL, "brk(%ld) returned %ld, sbrk before %ld, after %ld", nbrkpt, TEST_RETURN, cur_brk_val, aft_brk_val); } } } } cleanup(); tst_exit(); }
static void TestStoreRoot() { { CBook book; CHeightInfoX hix(2, 4, false, 60); CQPosition pos("---------------------------O*------*O---------------------------", true); const CValue value=32; const CValue cutoff=-100; book.StoreRoot(pos.BitBoard(), hix, value, cutoff); TEST(book.Size()==1); const CBookData* bd=book.FindData(pos.BitBoard()); TEST(bd!=NULL); TEST(bd->IsBranch()); TEST(!bd->IsUleaf()); TEST(!bd->IsLeaf()); TEST(!bd->IsProven()); TEST(bd->Hi()==hix); // don't test values as they won't be assigned. } { // now a solved root node CBook book; CQPosition pos("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*OOOOOO-----------------", true); const CValue value=-64*kStoneValue; CHeightInfoX hix(pos.NEmpty()-hSolverStart, 0, false, pos.NEmpty()); book.StoreRoot(pos.BitBoard(), hix, value, -100); TEST(book.Size()==1); const CBookData* bd=book.FindData(pos.BitBoard()); TEST(bd!=NULL); TEST(bd->IsLeaf()); TEST(bd->IsProven()); TEST(!bd->IsUleaf()); TEST(!bd->IsBranch()); TEST(bd->Hi()==hix); TEST(bd->Values().vMover==value+book.Boni().whiteBonus); TEST(bd->Values().vOpponent==value+book.Boni().whiteBonus); TEST(bd->Values().vHeuristic==value); } }
void TestFindQuestionableNode() { COsGame game; game.Initialize("8"); CQPosition initialPos(game, 0); CQPosition questionablePosition; CBook book; bool drawToMover; // The position is not in book. FindQuestionableNode should return NULL. bool isQuestionable = book.FindQuestionableNode(questionablePosition, drawToMover, initialPos, drawCutoff, deviationCutoff); TEST(!isQuestionable); // add the initial position to the book. FindQuestionableNode should return the initial position. const CBitBoard initialBitBoard(initialPos.BitBoard()); CMinimalReflection mr(initialBitBoard); CHeightInfoX heightInfoX(2, 4, false, initialBitBoard.NEmpty()); book.StoreLeaf(CMinimalReflection(initialBitBoard), heightInfoX, 0); isQuestionable = book.FindQuestionableNode(questionablePosition, drawToMover, initialPos, drawCutoff, deviationCutoff); TEST(isQuestionable); TEST(questionablePosition==initialPos); // add the initial position to the book with a deviation of the deviation cutoff // Since this is bigger than the threshold for deviations, we won't count it. book.StoreLeaf(CMinimalReflection(initialBitBoard), heightInfoX, deviationCutoff); isQuestionable = book.FindQuestionableNode(questionablePosition, drawToMover, initialPos, drawCutoff, deviationCutoff); TEST(!isQuestionable); // but if it's one less than the deviation cutoff, it's questionable book.StoreLeaf(CMinimalReflection(initialBitBoard), heightInfoX, deviationCutoff-1); isQuestionable = book.FindQuestionableNode(questionablePosition, drawToMover, initialPos, drawCutoff, deviationCutoff); TEST(isQuestionable); TEST(questionablePosition==initialPos); // Also if it's negative... at the deviation cutoff is ok, one more is questionable book.StoreLeaf(CMinimalReflection(initialBitBoard), heightInfoX, -deviationCutoff); isQuestionable = book.FindQuestionableNode(questionablePosition, drawToMover, initialPos, drawCutoff, deviationCutoff); TEST(!isQuestionable); book.StoreLeaf(CMinimalReflection(initialBitBoard), heightInfoX, 1-deviationCutoff); isQuestionable = book.FindQuestionableNode(questionablePosition, drawToMover, initialPos, drawCutoff, deviationCutoff); TEST(isQuestionable); TEST(questionablePosition==initialPos); // This node is a draw, at +3/-3.. so it's ok const CBookData* bookData = book.FindData(initialBitBoard); // casting to remove const is a really bad idea... but no other easy way to test CBookValue& bookValue = (CBookValue&)(bookData->Values()); bookValue.vHeuristic = 0; bookValue.vMover = drawCutoff; bookValue.vOpponent = - drawCutoff; isQuestionable = book.FindQuestionableNode(questionablePosition, drawToMover, initialPos, drawCutoff, deviationCutoff); TEST(!isQuestionable); TEST(questionablePosition==initialPos); CQPosition nextPos(initialPos); nextPos.MakeMove(CMove("F5")); const CBitBoard f5 = nextPos.BitBoard(); nextPos.MakeMove(CMove("D6")); const CBitBoard f5d6 = nextPos.BitBoard(); nextPos = initialPos; nextPos.MakeMove(CMove("F5")); nextPos.MakeMove(CMove("F6")); const CBitBoard f5f6 = nextPos.BitBoard(); // Now we have a questionable position, but it's not at the initial node // tree is: // f5 d6 : proven draw // f5 f6 : deviation with value drawValue book.StoreRoot(initialBitBoard, heightInfoX, 0, -16400); book.StoreRoot(f5, heightInfoX, 0, -16400); CHeightInfoX hixSolved = CHeightInfoX(f5f6.NEmpty(), 0, false, f5f6.NEmpty()); book.StoreLeaf(f5f6, hixSolved, 0); book.StoreLeaf(f5d6, heightInfoX, drawCutoff); book.NegamaxAll(); isQuestionable = book.FindQuestionableNode(questionablePosition, drawToMover, initialPos, drawCutoff, deviationCutoff); TEST(isQuestionable); TEST(CMinimalReflection(questionablePosition.BitBoard())==CMinimalReflection(f5d6)); // This position has a questionable node, but it's not on the draw tree so it's not returned CBook book2; book2.StoreRoot(initialBitBoard, heightInfoX, -deviationCutoff, -16400); book2.StoreRoot(f5, heightInfoX, deviationCutoff, -16400); book2.StoreLeaf(f5f6, heightInfoX, -deviationCutoff); book2.StoreLeaf(f5d6, heightInfoX, 0); book2.NegamaxAll(); isQuestionable = book2.FindQuestionableNode(questionablePosition, drawToMover, initialPos, drawCutoff, deviationCutoff); TEST(!isQuestionable); }
void TestThreading::runTests(IGameDef *) { TEST(testAtomicSemaphoreThread); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ pid_t cpid; /* process id of the child process */ int exit_status; /* exit status of child process */ sigset_t PendSig; /* variable to hold pending signal */ /* Parse standard options given to run the test. */ msg = parse_opts(ac, av, (option_t *) NULL, NULL); if (msg != (char *) NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } /* Perform global setup for test */ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /* Check looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* Reset Tst_count in case we are looping. */ Tst_count=0; /* * Call vfork(2) to create a child process without * fully copying the address space of parent. */ TEST(vfork()); /* check return code of vfork() */ if ((cpid = TEST_RETURN) == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "vfork() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else if (cpid == 0) { /* Child process */ /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Check whether the pending signal SIGUSR1 * in the parent is also pending in the child * process by storing it in a variable. */ if (sigpending(&PendSig) == -1) { tst_resm(TFAIL, "sigpending function " "failed in child"); _exit(1); } /* Check if SIGUSR1 is pending in child */ if (sigismember(&PendSig, SIGUSR1) != 0) { tst_resm(TFAIL, "SIGUSR1 also pending " "in child process"); _exit(1); } /* * Exit with normal exit code if everything * fine */ _exit(0); } } else { /* parent process */ /* * Let the parent process wait till child completes * its execution. */ wait(&exit_status); /* Check for the exit status of child process */ if (WEXITSTATUS(exit_status) == 0) { tst_resm(TPASS, "Call to vfork() " "successful"); } else if (WEXITSTATUS(exit_status) == 1) { tst_resm(TFAIL, \ "Child process exited abnormally"); } } Tst_count++; /* incr. TEST_LOOP counter */ } /* End for TEST_LOOPING */ /* Call cleanup() to undo setup done for the test. */ cleanup(); return 0; } /* End main */
static int do_test (void) { #if LDBL_MANT_DIG >= 106 volatile union { long double l; long long x[2]; } u, v; char buf[64]; #endif int result = 0; #if LDBL_MANT_DIG == 106 || LDBL_MANT_DIG == 113 # define COMPARE_LDBL(u, v) \ ((u).l == (v).l && (u).x[0] == (v).x[0] && (u).x[1] == (v).x[1]) #else # define COMPARE_LDBL(u, v) ((u).l == (v).l) #endif #define TEST(val) \ do \ { \ u.l = (val); \ snprintf (buf, sizeof buf, "%.30LgL", u.l); \ if (strcmp (buf, #val) != 0) \ { \ printf ("Error on line %d: %s != %s\n", __LINE__, buf, #val); \ result = 1; \ } \ if (sscanf (#val, "%Lg", &v.l) != 1 || !COMPARE_LDBL (u, v)) \ { \ printf ("Error sscanf on line %d: %.30Lg != %.30Lg\n", __LINE__, \ u.l, v.l); \ result = 1; \ } \ /* printf ("%s %Lg %016Lx %016Lx\n", #val, u.l, u.x[0], u.x[1]); */ \ } \ while (0) #if LDBL_MANT_DIG >= 106 # if LDBL_MANT_DIG == 106 TEST (2.22507385850719347803989925739e-308L); TEST (2.22507385850719397210554509863e-308L); TEST (2.22507385850720088902458687609e-308L); # endif TEST (2.22507385850720138309023271733e-308L); TEST (2.22507385850720187715587855858e-308L); TEST (2.2250738585074419930597574044e-308L); TEST (4.45014771701440227211481959342e-308L); TEST (4.45014771701440276618046543466e-308L); TEST (4.45014771701440375431175711716e-308L); TEST (4.45014771701440474244304879965e-308L); TEST (7.12023634722304600689881138745e-307L); TEST (1.13923781555569064960474854133e-305L); TEST (1.13777777777777776389998996996L); TEST (1.13777777777777765287768750745L); TEST (20988295479420645138.2044444444L); TEST (20988295479420643090.2044444444L); TEST (2.14668699894294423266045294316e-292L); # if LDBL_MANT_DIG == 106 TEST (-2.35993711055432139266626434123e-292L); TEST (6.26323524637968345414769634658e-302L); TEST (1.49327164802066885331814201989e-308L); TEST (3.71834550652787023640837473722e-308L); TEST (9.51896449671134907001349268087e-306L); # endif #endif return result; }
int main() { //fast access using program_language = l_language::l_vm; using compiler_flags = l_language::l_vm::compiler_flags; //source file std::string i_source = "scripts/function.ll"; int f_compier_flags = compiler_flags::EXECUTE; //compiler object program_language it_compiler; //add libs it_compiler.add_lib(l_language::l_base_lib); it_compiler.add_lib("io", l_language::l_io_lib); it_compiler.add_lib("os", l_language::l_os_lib); //read code // "source.it" std::ifstream source_file(i_source); std::string source((std::istreambuf_iterator<char>(source_file)), (std::istreambuf_iterator<char>())); //compile program_language::compiler_ouput compiler_ouput; compiler_ouput = it_compiler.compile(source,f_compier_flags); //ouput: if(compiler_ouput.m_type & program_language::ERRORS) { std::cout << compiler_ouput.m_errors; return -1; } //tests TEST("pow2", // test name pow2, // function 36.0f, // return 6.0f // args ); TEST("diff", // test name diff, // function 1.0f, // return 2.0f, 1.0f // args ); TEST("fib", // test name fib, // function 89.0f, // return 10.0f // args ); TEST("super", // test name super_test, // function 5.0f, // return 0.0f // args ); TEST("for of", // test name for_of_test, // function 15.0f, // return 0.0f // args ); TEST("for in", // test name for_in_test, // function 10.0f, // return 0.0f // args ); TEST_TYPE_OF("is int", // test name int_test, // function INT, // return type 0 // args ); TEST_TYPE_OF("is float", // test name float_test, // function FLOAT, // return type 0 // args ); TEST_TYPE_OF("is string", // test name string_test, // function STRING, // return type 0 // args ); std::vector<l_language::l_variable> array_test_values = { 1.2f, 3, l_language::l_string::const_new(it_compiler.get_gc(), "hello"), l_language::l_string::const_new(it_compiler.get_gc(), "l"), l_language::l_string::const_new(it_compiler.get_gc(), "language") }; TEST_ARRAY("generic test array", // test name array_test, // function array_test_values, // return 0 // args ); //1-100 int range_values = rand() % 100 + 1; TEST("for range(len) rand", // test name for_range_1_rand, // function gauss(range_values-1), // return range_values // args ); TEST("for like c rand", // test name for_c_like, // function 90, // return 0 // args ); //0-(range_values-1) int start_values = rand() % range_values - 1 ; TEST("for range(start,len) rand", // test name for_range_2_rand, // function gauss(range_values-1)-gauss(start_values), // return start_values,range_values // args ); std::vector<l_language::l_variable> array_range_values = { 1, 3 }; TEST_ARRAY("range(start,len,step)", // test name range_3, // function array_range_values, // return 1,5,2 // args ); //lambda calc test int rand_l_c_1 = rand() % 100 - 1 ; TEST("lambda calc 1", // test name lambda_calc_1, // function rand_l_c_1, // return rand_l_c_1 // args ); int rand_l_2_n = rand() % 100 - 1 ; int rand_l_2_c = rand() % 100 - 1 ; int rand_l_2_d = rand() % 100 - 1 ; int rand_l_2_ret = rand_l_2_n*(rand_l_2_c+rand_l_2_d); TEST("lambda calc 2", // test name lambda_calc_2, // function rand_l_2_ret, // return rand_l_2_n, rand_l_2_c, rand_l_2_d // args ); TEST("lambda calc fib", // test name lambda_calc_fib, // function 89.0f, // return 10.0f // args ); //print success std::cout << s_count_success << " of " << s_count_test << " successes" << std::endl; //print fails if(s_tests_fails.size()) for(const std::string& test_name : s_tests_fails) std::cout << "- failed \"" << test_name << "\" test" << std::endl; }
int main(int ac, char **av) { int lc, i; /* loop counter */ char *msg; /* message returned from parse_opts */ /* parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { if (testcase[i].setupfunc && testcase[i].setupfunc() == -1) { tst_resm(TWARN, "Failed to setup test %d." " Skipping test", i); continue; } else { TEST(syscall(__NR_swapoff, testcase[i].path)); } if (testcase[i].cleanfunc && testcase[i].cleanfunc() == -1) { tst_brkm(TBROK, cleanup, "cleanup failed," " quitting the test"); } /* check return code */ if ((TEST_RETURN == -1) && (TEST_ERRNO == testcase[i]. exp_errno)) { tst_resm(TPASS, "swapoff(2) expected failure;" " Got errno - %s : %s", testcase[i].exp_errval, testcase[i].err_desc); } else { tst_resm(TFAIL, "swapoff(2) failed to produce" " expected error; %d, errno" ": %s and got %d", testcase[i].exp_errno, testcase[i].exp_errval, TEST_ERRNO); if ((TEST_RETURN == 0) && (i == 2)) { if (syscall(__NR_swapon, "./swapfile01", 0) != 0) { tst_brkm(TBROK, cleanup, " Failed to turn on" " swap file"); } } } TEST_ERROR_LOG(TEST_ERRNO); } /*End of TEST LOOPS */ } /*Clean up and exit */ cleanup(); tst_exit(); } /*End of main */
/* * do_master_child() */ void do_master_child() { int lc; int pid; int status; for (lc = 0; TEST_LOOPING(lc); lc++) { int tst_fd; /* Reset tst_count in case we are looping */ tst_count = 0; if (setreuid(0, ltpuser->pw_uid) == -1) { perror("setfsuid failed"); exit(1); } /* Test 1: Check the process with new uid cannot open the file * with RDWR permissions. */ TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { printf("open succeeded unexpectedly\n"); close(tst_fd); exit(1); } if (TEST_ERRNO == EACCES) { printf("open failed with EACCES as expected\n"); } else { perror("open failed unexpectedly"); exit(1); } /* Test 2: Check a son process cannot open the file * with RDWR permissions. */ pid = FORK_OR_VFORK(); if (pid < 0) tst_brkm(TBROK, cleanup, "Fork failed"); if (pid == 0) { int tst_fd2; /* Test to open the file in son process */ TEST(tst_fd2 = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { printf("call succeeded unexpectedly\n"); close(tst_fd2); exit(1); } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == EACCES) { printf("open failed with EACCES as expected\n"); exit(0); } else { printf("open failed unexpectedly\n"); exit(1); } } else { /* Wait for son completion */ if (waitpid(pid, &status, 0) == -1) { perror("waitpid failed"); exit(1); } if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) exit(WEXITSTATUS(status)); } /* Test 3: Fallback to initial uid and check we can again open * the file with RDWR permissions. */ tst_count++; if (setreuid(0, 0) == -1) { perror("setfsuid failed"); exit(1); } TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN == -1) { perror("open failed unexpectedly"); exit(1); } else { printf("open call succeeded\n"); close(tst_fd); } } exit(0); }
/** @SYMTestCaseID SYSLIB-LOGENG-CT-0129 @SYMTestCaseDesc Test that a view only contains events that are suitable for a clients cabability @SYMTestPriority High @SYMTestActions See comments in the trest code below for further info. @SYMTestExpectedResults Should always succeed @SYMREQ REQ3431 */ LOCAL_C void TestEventViewWithFilterL(CLogClient& aClient) { // TestUtils::AddTestEventsL() --> should be called before this function. // It deletes the database, then... // adds 8 events - 2 are visible to clients with no capabilities // and 6 are of type KLogCallEventTypeUid, which is protected. TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0129 ")); CTestActive* active = new(ELeave)CTestActive; CleanupStack::PushL(active); CLogFilterList* list = new(ELeave)CLogFilterList; CleanupStack::PushL(list); CLogViewEvent* view = CLogViewEvent::NewL(aClient); CleanupStack::PushL(view); CLogFilter* filter = CLogFilter::NewL(); CleanupStack::PushL(filter); TLogString direction; aClient.GetString(direction, R_LOG_DIR_IN); // Test 1. // Of the 8 new events, 2 have KTestContact1 as the contact field // One of them is a secure type and the other isn't. // So, if running at hi capability, expect 2 events, else 1 TInt expectedEventCount = (TheHiCapability) ? 2 : 1; filter->SetContact(KTestContact1); list->AppendL(filter); active->StartL(); TEST(view->SetFilterL(*list, active->iStatus)); CActiveScheduler::Start(); TEST(view->CountL() == expectedEventCount); // Test 2. // Of the 8 new events, 6 have KTestContact2 as the contact field // One of them is a secure type and the other isn't. // The filters will be combined in the query, so expect // 8 events if running at hi capability, else 2 expectedEventCount = (TheHiCapability) ? 8 : 2; CleanupStack::Pop(); // filter filter = CLogFilter::NewL(); CleanupStack::PushL(filter); filter->SetContact(KTestContact2); list->AppendL(filter); active->StartL(); TEST(view->SetFilterL(*list, active->iStatus)); CActiveScheduler::Start(); TEST(view->CountL() == expectedEventCount); // Test 3. // Of the 8 new events, 7 have R_LOG_DIR_IN as the direction field. // Two of these are only visible for hi capability clients, the other one // can be viewed by all clients. expectedEventCount = (TheHiCapability) ? 7 : 1; CleanupStack::Pop(); // filter filter = CLogFilter::NewL(); CleanupStack::PushL(filter); filter->SetDirection(direction); list->AppendL(filter); active->StartL(); TEST(view->SetFilterL(*list, active->iStatus)); CActiveScheduler::Start(); TEST(view->CountL() == expectedEventCount); // clear up... list->ResetAndDestroy(); CleanupStack::Pop(); // filter CleanupStack::PopAndDestroy(3); // view, list, active }
int main(int ac, char **av) { int lc; char *msg; int results; /* Disable test if the version of the kernel is less than 2.6.17 */ if (((results = tst_kvercmp(2, 6, 17)) < 0)) { tst_resm(TWARN, "This test can only run on kernels that are "); tst_resm(TWARN, "2.6.17 and higher"); exit(0); } /* * parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /* * perform global setup for test */ setup(); /* * check if the current filesystem is nfs */ if (tst_is_cwd_nfs()) { tst_brkm(TCONF, cleanup, "Cannot do tee on a file located on an NFS filesystem"); } /* * check looping state if -c option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* * Call tee_test */ TEST(tee_test()); /* check return code */ if (TEST_RETURN < 0) { if (TEST_RETURN != -1) { TEST_ERRNO = -TEST_RETURN; } TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "tee() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * only perform functional verification if flag set (-f not given) */ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "tee() returned %ld", TEST_RETURN); } } } /* * cleanup and exit */ cleanup(); return (0); }
/** @SYMTestCaseID SYSLIB-LOGENG-CT-0126 @SYMTestCaseDesc Change the database configuration @SYMTestPriority High @SYMTestActions Low capability clients can't do this @SYMTestExpectedResults Should always succeed @SYMREQ REQ3431 */ LOCAL_C void TestChangeConfigL(CLogClient& aClient) { TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0126 ")); CTestActive* active = new(ELeave)CTestActive(); CleanupStack::PushL(active); TLogConfig configOld; active->StartL(); aClient.GetConfig(configOld, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); TLogConfig config; #ifdef _DEBUG TInt failCount = 0; #endif TBool finished = EFalse; TInt error; while(!finished) { error = KErrNone; config.iMaxLogSize = KTestMaxLogSize; config.iMaxRecentLogSize = KTestMaxRecentLogSize; config.iMaxEventAge = KTestMaxEventAge; __UHEAP_FAILNEXT(failCount++); aClient.ChangeConfig(config, active->iStatus); active->StartL(); CActiveScheduler::Start(); if (active->iStatus == KErrNone) finished = ETrue; else error = active->iStatus.Int(); __UHEAP_RESET; if ((error == KErrNoMemory) || (error == KErrPermissionDenied)) { active->StartL(); aClient.GetConfig(config, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); TEST(config.iMaxLogSize == configOld.iMaxLogSize); TEST(config.iMaxRecentLogSize == configOld.iMaxRecentLogSize); TEST(config.iMaxEventAge == configOld.iMaxEventAge); } else { TEST2(error, KErrNone); } if(! TheHiCapability) finished = TRUE; } if(TheHiCapability) { TEST(config.iMaxLogSize == KTestMaxLogSize); TEST(config.iMaxRecentLogSize == KTestMaxRecentLogSize); TEST(config.iMaxEventAge == KTestMaxEventAge); } else { TEST(config.iMaxLogSize == configOld.iMaxLogSize); TEST(config.iMaxRecentLogSize == configOld.iMaxRecentLogSize); TEST(config.iMaxEventAge == configOld.iMaxEventAge); } CleanupStack::PopAndDestroy(); // active }
/** @SYMTestCaseID SYSLIB-LOGENG-CT-0122 @SYMTestCaseDesc Tries to change existing event types. @SYMTestActions See the description and expected results. @SYMTestPriority High @SYMTestExpectedResults Should always succeed @SYMREQ REQ3431 */ LOCAL_C void TestChangeEventTypeL(CLogClient& aClient) { TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0122 ")); CTestActive* active = new(ELeave)CTestActive(); CleanupStack::PushL(active); CLogEventType* type = CLogEventType::NewL(); CleanupStack::PushL(type); type->SetUid(KTestEventUid); type->SetDescription(KTestEventDesc1); type->SetDescription(KTestEventDesc2); #ifdef _DEBUG TInt failCount = 0; #endif TBool finished = EFalse; TInt error; while(!finished) { error = KErrNone; type->SetDescription(KTestEventDesc2); type->SetLoggingEnabled(EFalse); __UHEAP_FAILNEXT(failCount++); aClient.ChangeEventType(*type, active->iStatus); active->StartL(); CActiveScheduler::Start(); if (active->iStatus == KErrNone) finished = ETrue; else error = active->iStatus.Int(); __UHEAP_RESET; if (error == KErrNoMemory) { active->StartL(); aClient.GetEventType(*type, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); TEST(type->Description() == KTestEventDesc1); TEST(type->LoggingEnabled()); } else { TEST2(error, TheHiCapability ? KErrNone : KErrPermissionDenied); if(!TheHiCapability) finished = TRUE; } } type->SetUid(KTestEventUid); active->StartL(); aClient.GetEventType(*type, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); if(TheHiCapability) { TEST(type->Uid() == KTestEventUid); TEST(type->Description() == KTestEventDesc2); TEST(type->LoggingEnabled() == EFalse); } else { TEST(type->Uid() == KTestEventUid); TEST(type->Description() == KTestEventDesc1); TEST(type->LoggingEnabled()); } CleanupStack::PopAndDestroy(2); // type, active }
/** @SYMTestCaseID SYSLIB-LOGENG-CT-0119 @SYMTestCaseDesc Tests AddEvent, GetEvent, ChangeEvent and DeleteEvent. @SYMTestPriority High @SYMTestActions See the description and expected results. @SYMTestExpectedResults 1. a client with sufficient capability succeed in all cases would expect the following... AddEvent - KErrNone GetEvent - KErrNone ChangeEvent - KErrNone DeleteEvent - KErrNone 2. a client with insufficient capability would expect the following results... AddEvent - KErrPermissionDenied GetEvent - KErrNone ChangeEvent - KErrPermissionDenied DeleteEvent - KErrPermissionDenied @SYMREQ REQ3431 */ LOCAL_C void TestBasicL(CLogClient& aClient) { TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0119 ")); CTestActive* active = new(ELeave)CTestActive(); CleanupStack::PushL(active); CLogEvent* event = CLogEvent::NewL(); CleanupStack::PushL(event); TTime now; now.UniversalTime(); event->SetEventType(KLogCallEventTypeUid); active->StartL(); aClient.AddEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied); if(!TheHiCapability) { TInt eventId = TestUtils::AddEventL(); TEST(eventId >= 0); event->SetId(eventId); } TEST(event->EventType() == KLogCallEventTypeUid); now = event->Time(); TLogId id = event->Id(); event->SetRemoteParty(KTestRemoteParty1); event->SetDirection(KTestDirection1); event->SetDurationType(KTestDurationType1); event->SetDuration(KTestDuration1); event->SetStatus(KTestStatus1); event->SetSubject(KTestSubject1); event->SetNumber(KTestNumber1); event->SetContact(KTestContact1); event->SetLink(KTestLink1); event->SetDataL(KTestData1); active->StartL(); aClient.ChangeEvent(*event, active->iStatus); CActiveScheduler::Start(); TheTest.Printf(_L("TestBasicL(), TheHiCapability=%d, event id=%d\r\n"), TheHiCapability, id); TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied); TEST(event->Id() == id ); TEST(event->EventType() == KLogCallEventTypeUid); if(TheHiCapability) { TEST(event->Description().Length() > 0); TEST(event->Time() == now); TEST(event->RemoteParty() == KTestRemoteParty1); TEST(event->Direction() == KTestDirection1); TEST(event->DurationType() == KTestDurationType1); TEST(event->Duration() == KTestDuration1); TEST(event->Status() == KTestStatus1); TEST(event->Subject() == KTestSubject1); TEST(event->Number() == KTestNumber1); TEST(event->Contact() == KTestContact1); TEST(event->Link() == KTestLink1); TEST(event->Data() == KTestData1); } CleanupStack::PopAndDestroy(); // event; event = CLogEvent::NewL(); CleanupStack::PushL(event); event->SetId(id); active->StartL(); aClient.GetEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied); if(TheHiCapability) { TEST(event->Id() == id); TEST(event->EventType() == KLogCallEventTypeUid); TEST(event->Description().Length() > 0); TEST(event->Time() == now); TEST(event->RemoteParty() == KTestRemoteParty1); TEST(event->Direction() == KTestDirection1); TEST(event->DurationType() == KTestDurationType1); TEST(event->Duration() == KTestDuration1); TEST(event->Status() == KTestStatus1); TEST(event->Subject() == KTestSubject1); TEST(event->Number() == KTestNumber1); TEST(event->Contact() == KTestContact1); TEST(event->Link() == KTestLink1); TEST(event->Data() == KTestData1); } active->StartL(); aClient.DeleteEvent(id, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied); active->StartL(); aClient.GetEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), TheHiCapability ? KErrNotFound : KErrPermissionDenied); // try to delete a non-existent event... active->StartL(); aClient.DeleteEvent(123, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNotFound); CleanupStack::PopAndDestroy(2); // event, active }
void test_read_2(void) { Value value = read_from_str("1x"); TEST(value.type == SYMBOL); }
/* * do_child() */ void do_child() { unsigned long req, rem, elapsed; /* usec */ struct timeval otime; /* time before child execution suspended */ struct timeval ntime; /* time after child resumes execution */ /* Note down the current time */ gettimeofday(&otime, NULL); /* * Call nanosleep() to suspend child process * for specified time 'tv_sec'. * Call should return before suspending execution * for the specified time due to receipt of signal * from Parent. */ TEST(nanosleep(&timereq, &timerem)); /* time after child resumes execution */ gettimeofday(&ntime, NULL); /* * Check whether the remaining sleep of child updated * in 'timerem' structure. * The time remaining should be equal to the * Total time for sleep - time spent on sleep bfr signal * Change precision from msec to usec. */ req = timereq.tv_sec * 1000000 + timereq.tv_nsec / 1000; rem = timerem.tv_sec * 1000000 + timerem.tv_nsec / 1000; elapsed = (ntime.tv_sec - otime.tv_sec) * 1000000 + ntime.tv_usec - otime.tv_usec; if (rem - (req - elapsed) > USEC_PRECISION) { tst_resm(TWARN, "This test could fail if the system was under load"); tst_resm(TWARN, "due to the limitation of the way it calculates the"); tst_resm(TWARN, "system call execution time."); tst_resm(TFAIL, "Remaining sleep time %lu usec doesn't " "match with the expected %lu usec time", rem, (req - elapsed)); exit(1); } /* Record the time before suspension */ gettimeofday(&otime, NULL); /* * Invoke nanosleep() again to suspend child * for the specified sleep time specified by * 'timereq' structure. */ TEST(nanosleep(&timereq, &timerem)); /* Record the time after suspension */ gettimeofday(&ntime, NULL); /* check return code of nanosleep() */ if (TEST_RETURN == -1) { tst_resm(TFAIL, "nanosleep() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); exit(1); } /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Verify whether child execution was * actually suspended for the remaining * sleep time specified by 'timerem' * structure. */ req = timereq.tv_sec * 1000000 + timereq.tv_nsec / 1000; elapsed = (ntime.tv_sec - otime.tv_sec) * 1000000 + ntime.tv_usec - otime.tv_usec; if (elapsed - req > USEC_PRECISION) { tst_resm(TWARN, "This test could fail if the system was under load"); tst_resm(TWARN, "due to the limitation of the way it calculates the"); tst_resm(TWARN, "system call execution time."); tst_resm(TFAIL, "Child execution not " "suspended for %jd seconds %lu nanoseconds", (intmax_t)timereq.tv_sec, timereq.tv_nsec); exit(1); } exit(0); } else { tst_resm(TPASS, "call succeeded"); exit(0); } }
int main(int ac, char **av) { int lc; char *msg; int ind; int offset; /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; offset = (lc % 100) * 4096; /* max size is 100 blocks */ for (ind = 0; Whence[ind] >= 0; ind++) { /* * Call lseek(2) */ TEST(lseek(Fd, (long)offset, Whence[ind])); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "lseek(%s, %d, 0) Failed, errno=%d : %s", Fname, offset, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "lseek(%s, %d, %d) returned %ld", Fname, offset, Whence[ind], TEST_RETURN); } else tst_count++; } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; int fflag; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Attempt to create a filesystem node with group id (sgid) * bit set on a directory with group id (sgid) bit set * such that, the node created by mknod(2) should have * group id (sgid) bit set and node's gid should be equal * to that of effective gid of the process. */ TEST(mknod(node_name, MODE_SGID, 0)); /* Check return code from mknod(2) */ if (TEST_RETURN == -1) { tst_resm(TFAIL, "mknod(%s, %#o, 0) failed, errno=%d : " "%s", node_name, MODE_SGID, TEST_ERRNO, strerror(TEST_ERRNO)); continue; } /* Set the functionality flag */ fflag = 1; /* Check for node's creation */ if (stat(node_name, &buf) < 0) { tst_resm(TFAIL, "stat() of %s failed, errno:%d", node_name, TEST_ERRNO); /* unset functionality flag */ fflag = 0; } /* Verify mode permissions of node */ if (!(buf.st_mode & S_ISGID)) { tst_resm(TFAIL, "%s: Incorrect modes, setgid bit not " "set", node_name); /* unset flag as functionality fails */ fflag = 0; } /* Verify group ID */ if (buf.st_gid != group2_gid) { tst_resm(TFAIL, "%s: Incorrect group", node_name); /* unset flag as functionality fails */ fflag = 0; } if (fflag) { tst_resm(TPASS, "Functionality of mknod(%s, " "%#o, 0) successful", node_name, MODE_SGID); } /* Remove the node for the next go `round */ if (unlink(node_name) == -1) { tst_resm(TWARN, "unlink(%s) failed, errno:%d %s", node_name, errno, strerror(errno)); } } /* Change the directory back to temporary directory */ SAFE_CHDIR(cleanup, ".."); /* * Invoke cleanup() to delete the test directories created * in the setup() and exit main(). */ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * TEST CASE: * Dont change either real or effective gid */ gid = getgid(); GID16_CHECK(gid, setregid, cleanup); egid = getegid(); GID16_CHECK(egid, setregid, cleanup); TEST(SETREGID(cleanup, -1, -1)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setregid - Dont change either real or effective gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "setregid - Dont change either real or effective gid returned %ld", TEST_RETURN); } /* * TEST CASE: * change effective to effective gid */ TEST(SETREGID(cleanup, -1, egid)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setregid - change effective to effective gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "setregid - change effective to effective gid returned %ld", TEST_RETURN); } /* * TEST CASE: * change real to real gid */ TEST(SETREGID(cleanup, gid, -1)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setregid - change real to real gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "setregid - change real to real gid returned %ld", TEST_RETURN); } /* * TEST CASE: * change effective to real gid */ TEST(SETREGID(cleanup, -1, gid)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setregid - change effective to real gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "setregid - change effective to real gid returned %ld", TEST_RETURN); } /* * TEST CASE: * try to change real to current real */ TEST(SETREGID(cleanup, gid, gid)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "setregid failed"); } else { tst_resm(TPASS, "setregid return %ld", TEST_RETURN); } } cleanup(); tst_exit(); }
void FUNCTION (test, func) (size_t stride, size_t N) { TYPE (gsl_vector) * v0; TYPE (gsl_vector) * v; QUALIFIED_VIEW(gsl_vector,view) view; size_t i, j; if (stride == 1) { v = FUNCTION (gsl_vector, calloc) (N); TEST(v->data == 0, "_calloc pointer"); TEST(v->size != N, "_calloc size"); TEST(v->stride != 1, "_calloc stride"); { int status = (FUNCTION(gsl_vector,isnull)(v) != 1); TEST (status, "_isnull" DESC " on calloc vector"); status = (FUNCTION(gsl_vector,ispos)(v) != 0); TEST (status, "_ispos" DESC " on calloc vector"); status = (FUNCTION(gsl_vector,isneg)(v) != 0); TEST (status, "_isneg" DESC " on calloc vector"); } FUNCTION (gsl_vector, free) (v); /* free whatever is in v */ } if (stride == 1) { v = FUNCTION (gsl_vector, alloc) (N); TEST(v->data == 0, "_alloc pointer"); TEST(v->size != N, "_alloc size"); TEST(v->stride != 1, "_alloc stride"); FUNCTION (gsl_vector, free) (v); /* free whatever is in v */ } if (stride == 1) { v0 = FUNCTION (gsl_vector, alloc) (N); view = FUNCTION (gsl_vector, subvector) (v0, 0, N); v = &view.vector; } else { v0 = FUNCTION (gsl_vector, alloc) (N * stride); for (i = 0; i < N*stride; i++) { BASE x = ZERO; GSL_REAL (x) = (ATOMIC)i; GSL_IMAG (x) = (ATOMIC)(i + 1234); FUNCTION (gsl_vector, set) (v0, i, x); } view = FUNCTION (gsl_vector, subvector_with_stride) (v0, 0, stride, N); v = &view.vector; } { int status = 0; for (i = 0; i < N; i++) { BASE x = ZERO; GSL_REAL (x) = (ATOMIC)i; GSL_IMAG (x) = (ATOMIC)(i + 1234); FUNCTION (gsl_vector, set) (v, i, x); } for (i = 0; i < N; i++) { if (v->data[2*i*stride] != (ATOMIC) (i) || v->data[2 * i * stride + 1] != (ATOMIC) (i + 1234)) status = 1; }; TEST(status,"_set" DESC " writes into array"); } { int status = 0; for (i = 0; i < N; i++) { BASE x, y; GSL_REAL (x) = (ATOMIC)i; GSL_IMAG (x) = (ATOMIC)(i + 1234); y = FUNCTION (gsl_vector, get) (v, i); if (!GSL_COMPLEX_EQ (x, y)) status = 1; }; TEST (status, "_get" DESC " reads from array"); } { int status = 0; for (i = 0; i < N; i++) { if (FUNCTION (gsl_vector, ptr) (v, i) != (BASE *)v->data + i*stride) status = 1; }; TEST (status, "_ptr" DESC " access to array"); } { int status = 0; for (i = 0; i < N; i++) { if (FUNCTION (gsl_vector, const_ptr) (v, i) != (BASE *)v->data + i*stride) status = 1; }; TEST (status, "_const_ptr" DESC " access to array"); } { int status = 0; for (i = 0; i < N; i++) { BASE x = ZERO; FUNCTION (gsl_vector, set) (v, i, x); } status = (FUNCTION(gsl_vector,isnull)(v) != 1); TEST (status, "_isnull" DESC " on null vector") ; status = (FUNCTION(gsl_vector,ispos)(v) != 0); TEST (status, "_ispos" DESC " on null vector") ; status = (FUNCTION(gsl_vector,isneg)(v) != 0); TEST (status, "_isneg" DESC " on null vector") ; } { int status = 0; for (i = 0; i < N; i++) { BASE x = ZERO; GSL_REAL (x) = (ATOMIC)i; GSL_IMAG (x) = (ATOMIC)(i + 1234); FUNCTION (gsl_vector, set) (v, i, x); } status = (FUNCTION(gsl_vector,isnull)(v) != 0); TEST (status, "_isnull" DESC " on non-null vector") ; status = (FUNCTION(gsl_vector,ispos)(v) != 0); TEST (status, "_ispos" DESC " on non-null vector") ; status = (FUNCTION(gsl_vector,ispos)(v) != 0); TEST (status, "_isneg" DESC " on non-null vector") ; } { int status = 0; FUNCTION (gsl_vector, set_zero) (v); for (i = 0; i < N; i++) { BASE x, y = ZERO; x = FUNCTION (gsl_vector, get) (v, i); if (!GSL_COMPLEX_EQ (x, y)) status = 1; }; TEST (status, "_setzero" DESC " on non-null vector") ; } { int status = 0; BASE x; GSL_REAL (x) = (ATOMIC)27; GSL_IMAG (x) = (ATOMIC)(27 + 1234); FUNCTION (gsl_vector, set_all) (v, x); for (i = 0; i < N; i++) { BASE y = FUNCTION (gsl_vector, get) (v, i); if (!GSL_COMPLEX_EQ (x, y)) status = 1; }; TEST (status, "_setall" DESC " to non-zero value") ; } { int status = 0; for (i = 0; i < N; i++) { FUNCTION (gsl_vector, set_basis) (v, i); for (j = 0; j < N; j++) { BASE x = FUNCTION (gsl_vector, get) (v, j); BASE one = ONE; BASE zero = ZERO; if (i == j) { if (!GSL_COMPLEX_EQ (x, one)) status = 1 ; } else { if (!GSL_COMPLEX_EQ (x, zero)) status = 1; } }; } TEST (status, "_setbasis" DESC " over range") ; } for (i = 0; i < N; i++) { BASE x = ZERO; GSL_REAL (x) = (ATOMIC)i; GSL_IMAG (x) = (ATOMIC)(i + 1234); FUNCTION (gsl_vector, set) (v, i, x); } { int status; BASE x, y, r, s ; GSL_REAL(x) = 2 ; GSL_IMAG(x) = 2 + 1234; GSL_REAL(y) = 5 ; GSL_IMAG(y) = 5 + 1234; FUNCTION (gsl_vector,swap_elements) (v, 2, 5) ; r = FUNCTION(gsl_vector,get)(v,2); s = FUNCTION(gsl_vector,get)(v,5); status = ! GSL_COMPLEX_EQ(r,y) ; status |= ! GSL_COMPLEX_EQ(s,x) ; FUNCTION (gsl_vector,swap_elements) (v, 2, 5) ; r = FUNCTION(gsl_vector,get)(v,2); s = FUNCTION(gsl_vector,get)(v,5); status |= ! GSL_COMPLEX_EQ(r,x) ; status |= ! GSL_COMPLEX_EQ(s,y) ; TEST (status, "_swap_elements" DESC " exchanges elements") ; } { int status = 0; FUNCTION (gsl_vector,reverse) (v) ; for (i = 0; i < N; i++) { BASE x,r ; GSL_REAL(x) = (ATOMIC)(N - i - 1) ; GSL_IMAG(x) = (ATOMIC)(N - i - 1 + 1234); r = FUNCTION (gsl_vector, get) (v, i); status |= !GSL_COMPLEX_EQ(r,x); } gsl_test (status, NAME(gsl_vector) "_reverse" DESC " reverses elements") ; } { int status = 0; QUALIFIED_VIEW(gsl_vector,view) v1 = FUNCTION(gsl_vector, view_array) (v->data, N*stride); for (i = 0; i < N; i++) { BASE x = FUNCTION (gsl_vector, get) (&v1.vector, i*stride) ; BASE y = FUNCTION (gsl_vector, get) (v, i); if (!GSL_COMPLEX_EQ(x,y)) status = 1; }; TEST (status, "_view_array" DESC); } { int status = 0; QUALIFIED_VIEW(gsl_vector,view) v1 = FUNCTION(gsl_vector, view_array_with_stride) (v->data, stride, N*stride); for (i = 0; i < N; i++) { BASE x = FUNCTION (gsl_vector, get) (&v1.vector, i) ; BASE y = FUNCTION (gsl_vector, get) (v, i); if (!GSL_COMPLEX_EQ(x,y)) status = 1; }; TEST (status, "_view_array_with_stride" DESC); } { int status = 0; QUALIFIED_VIEW(gsl_vector,view) v1 = FUNCTION(gsl_vector, subvector) (v, N/3, N/2); for (i = 0; i < N/2; i++) { BASE x = FUNCTION (gsl_vector, get) (&v1.vector, i) ; BASE y = FUNCTION (gsl_vector, get) (v, (N/3)+i); if (!GSL_COMPLEX_EQ(x,y)) status = 1; }; TEST (status, "_view_subvector" DESC); } { int status = 0; QUALIFIED_VIEW(gsl_vector,view) v1 = FUNCTION(gsl_vector, subvector_with_stride) (v, N/5, 3, N/4); for (i = 0; i < N/4; i++) { BASE x = FUNCTION (gsl_vector, get) (&v1.vector, i) ; BASE y = FUNCTION (gsl_vector, get) (v, (N/5)+3*i); if (!GSL_COMPLEX_EQ(x,y)) status = 1; }; TEST (status, "_view_subvector_with_stride" DESC); } { int status = 0; QUALIFIED_REAL_VIEW(gsl_vector,view) vv = FUNCTION(gsl_vector, real) (v); for (i = 0; i < N; i++) { ATOMIC xr = REAL_VIEW (gsl_vector, get) (&vv.vector, i) ; BASE y = FUNCTION (gsl_vector, get) (v, i); ATOMIC yr = GSL_REAL(y); if (xr != yr) status = 1; }; TEST (status, "_real" DESC); } { int status = 0; QUALIFIED_REAL_VIEW(gsl_vector,view) vv = FUNCTION(gsl_vector, imag) (v); for (i = 0; i < N; i++) { ATOMIC xr = REAL_VIEW (gsl_vector, get) (&vv.vector, i) ; BASE y = FUNCTION (gsl_vector, get) (v, i); ATOMIC yr = GSL_IMAG(y); if (xr != yr) status = 1; }; TEST (status, "_imag" DESC); } FUNCTION (gsl_vector, free) (v0); /* free whatever is in v */ }
int main(int ac, char **av) { int lc; int i; /* Check this system has fadvise64 system which is used in posix_fadvise. */ if ((_FILE_OFFSET_BITS != 64) && (__NR_fadvise64 == 0)) { tst_resm(TWARN, "This test can only run on kernels that implements "); tst_resm(TWARN, "fadvise64 which is used from posix_fadvise"); exit(0); } /* Disable test if the version of the kernel is less than 2.6.16 */ if ((tst_kvercmp(2, 6, 16)) < 0) { tst_resm(TWARN, "This test can only run on kernels that are "); tst_resm(TWARN, "2.6.16 and higher"); exit(0); } /* * parse standard options */ tst_parse_opts(ac, av, NULL, NULL); /* * perform global setup for test */ setup(); /* * check looping state if -i option given on the command line */ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* loop through the test cases */ for (i = 0; i < TST_TOTAL; i++) { TEST(posix_fadvise (TC[i].fd, TC[i].offset, TC[i].len, TC[i].advice)); if (TEST_RETURN == 0) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } /* Man page says: "On error, an error number is returned." */ if (TEST_RETURN == TC[i].error) { tst_resm(TPASS, "expected failure - " "returned value = %ld : %s", TEST_RETURN, strerror(TEST_RETURN)); } else { tst_resm(TFAIL, "unexpected return value - %ld : %s - " "expected %d", TEST_RETURN, strerror(TEST_RETURN), TC[i].error); } } } /* * cleanup and exit */ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *ptr; /* message returned from parse_opts */ gid_t group; int i; int entries; /* number of group entries */ initgroups("root", 0); if ((ptr = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", ptr); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; TEST(getgroups(-1, gidset)); if (TEST_RETURN == 0) tst_resm(TFAIL, "getgroups succeeded unexpectedly"); else if (STD_FUNCTIONAL_TEST) { if (errno == EINVAL) tst_resm(TPASS, "getgroups failed as expected with EINVAL"); else tst_resm(TFAIL | TTERRNO, "getgroups didn't fail as expected with EINVAL"); } /* * Check that if ngrps is zero that the number of groups is * return and the the gidset array is not modified. * This is a POSIX special case. */ memset(gidset, 052, NGROUPS); memset(cmpset, 052, NGROUPS); TEST(getgroups(0, gidset)); if (TEST_RETURN == -1) tst_resm(TFAIL | TTERRNO, "getgroups failed"); else if (STD_FUNCTIONAL_TEST) { if (memcmp(cmpset, gidset, NGROUPS) != 0) tst_resm(TFAIL, "getgroups modified the gidset array"); else tst_resm(TPASS, "getgroups did not modify the gidset " "array"); } /* * Check to see that is -1 is returned and errno is set to * EINVAL when ngroups is not big enough to hold all groups. */ if (TEST_RETURN <= 1) tst_resm(TCONF, "getgroups returned %ld; unable to test that using ngrps >=1 but less than number of grps", TEST_RETURN); else { TEST(getgroups(TEST_RETURN - 1, gidset)); if (TEST_RETURN == -1) { if (STD_FUNCTIONAL_TEST) { if (errno == EINVAL) tst_resm(TPASS, "getgroups failed as " "expected with EINVAL"); else tst_resm(TFAIL | TERRNO, "getgroups didn't fail " "with EINVAL"); } } else tst_resm(TFAIL, "getgroups succeeded unexpectedly with %ld", TEST_RETURN); } TEST(getgroups(NGROUPS, gidset)); if ((entries = TEST_RETURN) == -1) tst_resm(TFAIL | TTERRNO, "getgroups failed unexpectedly"); else if (STD_FUNCTIONAL_TEST) { group = getgid(); for (i = 0; i < entries; i++) if (gidset[i] == group) { tst_resm(TPASS, "getgroups(NGROUPS,gidset) " "returned %d contains gid %d " "(from getgid)", entries, group); break; } if (i == entries) tst_resm(TFAIL, "getgroups(NGROUPS,gidset) ret %d, does " "not contain gid %d (from getgid)", entries, group); } } cleanup(); tst_exit(); }
void TestCollision::runTests(IGameDef *gamedef) { TEST(testAxisAlignedCollision); }
teJIP_Status eJIP_PrintNetworkContent(tsJIP_Context *psJIP_Context) { //PRIVATE_CONTEXT(psJIP_Context); tsNode *psNode; tsMib *psMib; tsVar *psVar; DBG_vPrintf(DBG_FUNCTION_CALLS, "%s\n", __FUNCTION__); printf("Network: \n"); eJIP_Lock(psJIP_Context); psNode = psJIP_Context->sNetwork.psNodes; while (psNode) { printf(" Node: "); DBG_vPrintf_IPv6Address(1, psNode->sNode_Address.sin6_addr); printf(" Device ID: 0x%08x\n", psNode->u32DeviceId); psMib = psNode->psMibs; while (psMib) { printf(" Mib: 0x%08x, %s\n", psMib->u32MibId, psMib->pcName); psVar = psMib->psVars; while (psVar) { printf(" Var: %s%s\n", psVar->pcName, psVar->eEnable == E_JIP_VAR_DISABLED ? " (disabled)": ""); //DBG_vPrintf_IPv6Address(1, psNode->sNode_Address); printf(" "); switch (psVar->eVarType) { #define TEST(a) case (a): printf(#a); break TEST(E_JIP_VAR_TYPE_INT8); TEST(E_JIP_VAR_TYPE_UINT8); TEST(E_JIP_VAR_TYPE_INT16); TEST(E_JIP_VAR_TYPE_UINT16); TEST(E_JIP_VAR_TYPE_INT32); TEST(E_JIP_VAR_TYPE_UINT32); TEST(E_JIP_VAR_TYPE_INT64); TEST(E_JIP_VAR_TYPE_UINT64); TEST(E_JIP_VAR_TYPE_FLT); TEST(E_JIP_VAR_TYPE_DBL); TEST(E_JIP_VAR_TYPE_STR); TEST(E_JIP_VAR_TYPE_BLOB); TEST(E_JIP_VAR_TYPE_TABLE_BLOB); default: printf("Unknown Type"); #undef TEST } printf(", "); switch (psVar->eAccessType) { #define TEST(a) case (a): printf(#a); break TEST(E_JIP_ACCESS_TYPE_CONST); TEST(E_JIP_ACCESS_TYPE_READ_ONLY); TEST(E_JIP_ACCESS_TYPE_READ_WRITE); default: printf("Unknown Access Type"); #undef TEST } printf(", "); switch (psVar->eSecurity) { #define TEST(a) case (a): printf(#a); break TEST(E_JIP_SECURITY_NONE); default: printf("Unknown Security Type"); #undef TEST } printf("\n"); printf(" Value: "); if (psVar->pvData) { switch (psVar->eVarType) { #define TEST(a, b, c) case (a): printf(b, *psVar->c); break TEST(E_JIP_VAR_TYPE_INT8, "%d\n\r", pi8Data); TEST(E_JIP_VAR_TYPE_UINT8, "%u\n\r", pu8Data); TEST(E_JIP_VAR_TYPE_INT16, "%d\n\r", pi16Data); TEST(E_JIP_VAR_TYPE_UINT16, "%u\n\r", pu16Data); TEST(E_JIP_VAR_TYPE_INT32, "%d\n\r", pi32Data); TEST(E_JIP_VAR_TYPE_UINT32, "%u\n\r", pu32Data); TEST(E_JIP_VAR_TYPE_INT64, "%lld\n\r", pi64Data); TEST(E_JIP_VAR_TYPE_UINT64, "%llu\n\r", pu64Data); TEST(E_JIP_VAR_TYPE_FLT, "%f\n\r", pfData); TEST(E_JIP_VAR_TYPE_DBL, "%f\n\r", pdData); case (E_JIP_VAR_TYPE_STR): printf("%s\n", psVar->pcData); break; case (E_JIP_VAR_TYPE_BLOB): { uint32_t i; printf("{"); for (i = 0; i < psVar->u8Size; i++) { printf(" 0x%02x", psVar->pbData[i]); } printf(" }\n"); break; } case (E_JIP_VAR_TYPE_TABLE_BLOB): { tsTableRow *psTableRow; int i; printf("\n"); for (i = 0; i < psVar->ptData->u32NumRows; i++) { psTableRow = &psVar->ptData->psRows[i]; if (psTableRow->pvData) { uint32_t j; printf(" %03d {", i); for (j = 0; j < psTableRow->u32Length; j++) { printf(" 0x%02x", psTableRow->pbData[j]); } printf(" }\n"); } } break; } default: printf("Unknown Type\n"); #undef TEST } } else { printf("?\n"); } printf("\n"); psVar = psVar->psNext; } psMib = psMib->psNext; } psNode = psNode->psNext; } eJIP_Unlock(psJIP_Context); return E_JIP_OK; }
int main(int ac, char **av) { int lc; char *msg; void check_functionality(void); int r_val; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); /* global setup */ for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* get the name of the test dirctory */ if ((temp_dir = (getcwd(temp_dir, 0))) == NULL) tst_brkm(TBROK, cleanup, "getcwd failed"); /* * create a new directory and open it */ if ((r_val = mkdir(TEST_DIR, MODES)) == -1) tst_brkm(TBROK, cleanup, "mkdir failed"); if ((fd = open(TEST_DIR, O_RDONLY)) == -1) tst_brkm(TBROK, cleanup, "open of directory failed"); TEST(fchdir(fd)); if (TEST_RETURN == -1) tst_brkm(TFAIL | TTERRNO, cleanup, "fchdir call failed"); else { if (STD_FUNCTIONAL_TEST) check_functionality(); else tst_resm(TPASS, "call succeeded"); } /* * clean up things in case we are looping */ /* * NOTE: in case of failure here, we need to use "tst_resm()" * and not "tst_brkm()". This is because if we get to this * point, we have already set a PASS or FAIL for the test * and "tst_brkm()" won't report as we might expect. */ /* chdir back to our temporary work directory */ if ((r_val = chdir("..")) == -1) tst_resm(TBROK | TERRNO, "chdir failed"); if ((r_val = rmdir(TEST_DIR)) == -1) tst_resm(TBROK | TERRNO, "rmdir failed"); free(temp_dir); temp_dir = NULL; } cleanup(); tst_exit(); }
const char *pcJIP_strerror(teJIP_Status eStatus) { const char *pcResult; switch (eStatus) { #define TEST(a, b) case (a): pcResult = b; break /* These statuses are used by libJIP and pass over the network */ TEST(E_JIP_OK, "Success"); TEST(E_JIP_ERROR_TIMEOUT, "Operation timed out"); TEST(E_JIP_ERROR_BAD_MIB_INDEX, "Bad MIB Index/ID"); TEST(E_JIP_ERROR_BAD_VAR_INDEX, "Bad variable index"); TEST(E_JIP_ERROR_NO_ACCESS, "Access denied"); TEST(E_JIP_ERROR_BAD_BUFFER_SIZE, "Bad buffer size"); TEST(E_JIP_ERROR_WRONG_TYPE, "Incorrect variable data type"); TEST(E_JIP_ERROR_BAD_VALUE, "Invalid value for variable"); TEST(E_JIP_ERROR_DISABLED, "Variable is disabled"); TEST(E_JIP_ERROR_FAILED, "Failed"); /* These statuses are used by libJIP */ TEST(E_JIP_ERROR_BAD_DEVICE_ID, "Bad Device ID"); TEST(E_JIP_ERROR_NETWORK, "Network Error"); TEST(E_JIP_ERROR_WOULD_BLOCK, "Operation would block"); TEST(E_JIP_ERROR_NO_MEM, "Memory allocation failed"); TEST(E_JIP_ERROR_WRONG_CONTEXT, "Wrong context"); default: pcResult = "Unknown status"; } return pcResult; }
//! Test CBook::StoreSubposition(). //! While we're at it, test negamaxing as well, so store the parent position //! as a branch node and see if it's assigned the right value. static void TestStoreSubposition() { { // test StoreSubposition() when there is no pass after the move. CBook book; CQPosition pos; pos.Initialize(); const CMoveValue mv(F5, 41); CHeightInfoX hix(2, 4, false, pos.NEmpty()); // store subpos in book book.StoreSubposition(pos, mv, hix); TEST(book.Size()==1); // test that subpos went in correctly CQPosition posSub(pos); posSub.MakeMove(mv.move); CHeightInfoX hixSub(1, 4, false, posSub.NEmpty()-1); TestULeafPos(book, posSub, -mv.value, hixSub); // test that pos is valued correctly when we negamax book.StoreRoot(pos.BitBoard(), hix, mv.value, -100); book.NegamaxAll(); const CBookData* pbd=book.FindData(pos.BitBoard()); TEST(pbd!=NULL); TEST(pbd->Values().vHeuristic==mv.value); } { // test StoreSubposition() when there is a pass after the move. CBook book; CQPosition pos("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*******-----------------", false); CMoveValue mv(A7, 64*kStoneValue); CHeightInfoX hix(2, 4, false, pos.NEmpty()); // store subpos in book book.StoreSubposition(pos, mv, hix); TEST(book.Size()==1); // test that subpos went in correctly CQPosition posSub(pos); posSub.MakeMoveAndPass(mv.move); CHeightInfoX hixSub(1, 4, false, posSub.NEmpty()-1); TestULeafPos(book, posSub, mv.value, hixSub); // test that pos is valued correctly when we negamax book.StoreRoot(pos.BitBoard(), hix, mv.value, -100); book.NegamaxAll(); const CBookData* pbd=book.FindData(pos.BitBoard()); TEST(pbd!=NULL); TEST(pbd->Values().vHeuristic==mv.value); } { // test StoreSubposition() when there are two passes after the move. // no subposition should be added to the book (we don't store terminal nodes in book.) CBook book; CQPosition pos("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO******-----------------", false); CMoveValue mv; mv.move=H6; mv.value=64*kStoneValue; CHeightInfoX hix(2, 4, false, pos.NEmpty()); // store subpos in book book.StoreSubposition(pos, mv, hix); TEST(book.Size()==0); // test that pos is valued correctly when we negamax book.StoreRoot(pos.BitBoard(), hix, mv.value, -100); book.NegamaxAll(); const CBookData* pbd=book.FindData(pos.BitBoard()); TEST(pbd!=NULL); TEST(pbd->Values().vHeuristic==mv.value); } }
int main(int ac, char **av) { struct stat stat_buf; /* stat structure buffer */ int lc; const char *msg; char *file_name; /* ptr. for file name whose mode is modified */ char *test_desc; /* test specific error message */ int ind; /* counter to test different test conditions */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /* * Invoke setup function to call individual test setup functions * to simulate test conditions. */ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (ind = 0; Test_cases[ind].desc != NULL; ind++) { file_name = Test_cases[ind].pathname; test_desc = Test_cases[ind].desc; #if !defined(UCLINUX) if (file_name == High_address_node) { file_name = (char *)get_high_address(); } #endif /* * Call stat(2) to test different test conditions. * verify that it fails with -1 return value and * sets appropriate errno. */ TEST(stat(file_name, &stat_buf)); /* Check return code from stat(2) */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == Test_cases[ind].exp_errno) { tst_resm(TPASS, "stat() fails, %s, errno:%d", test_desc, TEST_ERRNO); } else { tst_resm(TFAIL, "stat() fails, %s, errno:%d, expected errno:%d", test_desc, TEST_ERRNO, Test_cases[ind].exp_errno); } } else { tst_resm(TFAIL, "stat(2) returned %ld, expected -1, errno:%d", TEST_RETURN, Test_cases[ind].exp_errno); } } tst_count++; /* incr TEST_LOOP counter */ } /* * Invoke cleanup() to delete the test directory/file(s) created * in the setup(). */ cleanup(); tst_exit(); }
static void TestHash(char* bytes, int length, u4 expected) { HashInit(); HashChunk(bytes, length); TEST(hash_a == expected); }
bool LimitedFileStream::tell(int& aPos) const { TEST(FileStream::tell(aPos)); aPos -= mStartPos; return true; }