TEST_F(EventsDatabaseTests, test_record_indexing) { auto sub = std::make_shared<DBFakeEventSubscriber>(); auto status = sub->testAdd(2); status = sub->testAdd(11); status = sub->testAdd(61); status = sub->testAdd((1 * 3600) + 1); status = sub->testAdd((2 * 3600) + 1); // An "all" range, will pick up everything in the largest index. auto indexes = sub->getIndexes(0, 3 * 3600); auto output = boost::algorithm::join(indexes, ", "); EXPECT_EQ("60.0, 60.1, 60.60, 60.120", output); // Restrict range to "most specific", which is an index by 10. indexes = sub->getIndexes(0, 5); output = boost::algorithm::join(indexes, ", "); // The order 10, 0th index include results with t = [0, 10). EXPECT_EQ("60.0", output); // Add specific indexes to the upper bound. status = sub->testAdd((2 * 3600) + 11); status = sub->testAdd((2 * 3600) + 61); indexes = sub->getIndexes(2 * 3600, (2 * 3600) + 62); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ("60.120, 60.121", output); // Request specific lower and upper bounding. indexes = sub->getIndexes(2, (2 * 3600) + 62); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ("60.0, 60.1, 60.60, 60.120, 60.121", output); }
TEST_F(EventsDatabaseTests, test_gentable) { auto sub = std::make_shared<DBFakeEventSubscriber>(); // Lie about the tool type to enable optimizations. auto default_type = kToolType; kToolType = OSQUERY_TOOL_DAEMON; ASSERT_EQ(sub->optimize_time_, 0U); ASSERT_EQ(sub->expire_time_, 0U); sub->testAdd(getUnixTime() - 1); sub->testAdd(getUnixTime()); sub->testAdd(getUnixTime() + 1); // Test the expire workflow by creating a short expiration time. FLAGS_events_expiry = 10; std::vector<std::string> keys; scanDatabaseKeys("events", keys); EXPECT_GT(keys.size(), 10U); // Perform a "select" equivalent. QueryContext context; auto results = sub->genTable(context); // Expect all non-expired results: 11, + EXPECT_EQ(results.size(), 9U); // The expiration time is now - events_expiry. EXPECT_GT(sub->expire_time_, getUnixTime() - (FLAGS_events_expiry * 2)); EXPECT_LT(sub->expire_time_, getUnixTime()); // The optimize time will be changed too. ASSERT_GT(sub->optimize_time_, 0U); // Restore the tool type. kToolType = default_type; results = sub->genTable(context); EXPECT_EQ(results.size(), 3U); results = sub->genTable(context); EXPECT_EQ(results.size(), 3U); // The optimize time should have been written to the database. // It should be the same as the current (relative) optimize time. std::string content; getDatabaseValue("events", "optimize.DBFakePublisher.DBFakeSubscriber", content); EXPECT_EQ(std::to_string(sub->optimize_time_), content); keys.clear(); scanDatabaseKeys("events", keys); EXPECT_LT(keys.size(), 30U); }
TEST_F(EventsDatabaseTests, test_expire_check) { auto sub = std::make_shared<DBFakeEventSubscriber>(); // Set the max number of buffered events to something reasonably small. FLAGS_events_max = 10; auto t = 10000; // We are still at the mercy of the opaque EVENTS_CHECKPOINT define. for (size_t x = 0; x < 3; x++) { size_t num_events = 256 * x; for (size_t i = 0; i < num_events; i++) { sub->testAdd(t++); } // Since events tests are dependent, expect 257 + 3 events. QueryContext context; auto results = sub->genTable(context); if (x == 0) { // The first iteration is dependent on previous test state. continue; } // The number of events should remain constant. // In practice there may be an event still in the write queue. EXPECT_LT(results.size(), 60U); } // Try again, this time with a scan for (size_t k = 0; k < 3; k++) { for (size_t x = 0; x < 3; x++) { size_t num_events = 256 * x; for (size_t i = 0; i < num_events; i++) { sub->testAdd(t++); } // Records hold the event_id + time indexes. // Data hosts the event_id + JSON content. auto record_key = "records." + sub->dbNamespace(); auto data_key = "data." + sub->dbNamespace(); std::vector<std::string> records, datas; scanDatabaseKeys(kEvents, records, record_key); scanDatabaseKeys(kEvents, datas, data_key); EXPECT_LT(records.size(), 20U); EXPECT_LT(datas.size(), 60U); } } }
int main(void) { testAdd(); testRemove(); return 0; }
/** * @brief Main program for testextra. */ int main(int argc, char const * const * argv) { int verbosity = 0; if (argc == 2) { int nread; int ret = sscanf(argv[1], "%d%n", &verbosity, &nread); if (ret != 1 || argv[1][nread]) { fprintf(stderr, "Usage: %s [verbosity]\n", argv[0]); return -1; } } if (testBdd(verbosity) != 0) return -1; if (testAdd(verbosity) != 0) return -1; if (testZdd(verbosity) != 0) return -1; if (testApa(verbosity) != 0) return -1; if (testCount(verbosity) != 0) return -1; if (testLdbl(verbosity) != 0) return -1; if (testTimeout(verbosity) != 0) return -1; return 0; }
TEST_F(EventsDatabaseTests, test_record_range) { auto sub = std::make_shared<DBFakeEventSubscriber>(); auto status = sub->testAdd(1); status = sub->testAdd(2); status = sub->testAdd(11); status = sub->testAdd(61); status = sub->testAdd((1 * 3600) + 1); status = sub->testAdd((2 * 3600) + 1); // Search within a specific record range. auto indexes = sub->getIndexes(0, 10); EXPECT_EQ(1U, indexes.size()); auto records = sub->getRecords(indexes); // This will return 3 results, ::get filters records by an absolute range. EXPECT_EQ(3U, records.size()); // 1, 2, 11 // Search within a large bound. indexes = sub->getIndexes(3, 3601); // This will include the 0-10 bucket meaning 1, 2 will show up. records = sub->getRecords(indexes); EXPECT_EQ(5U, records.size()); // 1, 2, 11, 61, 3601 // Get all of the records. indexes = sub->getIndexes(0, 3 * 3600); records = sub->getRecords(indexes); EXPECT_EQ(6U, records.size()); // 1, 2, 11, 61, 3601, 7201 // stop = 0 is an alias for everything. indexes = sub->getIndexes(0, 0); records = sub->getRecords(indexes); EXPECT_EQ(6U, records.size()); for (size_t j = 0; j < 30; j++) { // 110 is 10 below an index (60.2). sub->testAdd(110 + static_cast<int>(j)); } indexes = sub->getIndexes(110, 0); auto output = boost::algorithm::join(indexes, ", "); EXPECT_EQ("60.1, 60.2, 60.60, 60.120", output); records = sub->getRecords(indexes); EXPECT_EQ(33U, records.size()); // (61) 110 - 139 + 3601, 7201 }
TEST_F(EventsDatabaseTests, test_record_indexing) { auto sub = std::make_shared<DBFakeEventSubscriber>(); auto status = sub->testAdd(2); status = sub->testAdd(11); status = sub->testAdd(61); status = sub->testAdd((1 * 3600) + 1); status = sub->testAdd((2 * 3600) + 1); // An "all" range, will pick up everything in the largest index. auto indexes = sub->getIndexes(0, 3 * 3600); auto output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "3600.0, 3600.1, 3600.2"); // Restrict range to "most specific", which is an index by 10. indexes = sub->getIndexes(0, 5); output = boost::algorithm::join(indexes, ", "); // The order 10, 0th index include results with t = [0, 10). EXPECT_EQ(output, "10.0"); // Get a mix of indexes for the lower bounding. indexes = sub->getIndexes(2, (3 * 3600)); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "10.0, 10.1, 3600.1, 3600.2, 60.1"); // Rare, but test ONLY intermediate indexes. // Provide an optional third parameter to getIndexes: 1 = 10,(60),3600. indexes = sub->getIndexes(2, (3 * 3600), 1); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "60.0, 60.1, 60.120, 60.60"); // Add specific indexes to the upper bound. status = sub->testAdd((2 * 3600) + 11); status = sub->testAdd((2 * 3600) + 61); indexes = sub->getIndexes(2 * 3600, (2 * 3600) + 62); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "10.726, 60.120"); // Request specific lower and upper bounding. indexes = sub->getIndexes(2, (2 * 3600) + 62); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "10.0, 10.1, 10.726, 3600.1, 60.1, 60.120"); }
void test(){ testAdd(); testSub(); testMult(); testScale(); testEquals(); testDivision(); testAbsolute(); testArgument(); printf("All passed!\n"); }
int main (int argc, char *argv[]){ testAdd(); testDelete(); testAppend(); testReverse(); testZip(); printf("All tests passed! You are awesome!\n"); return EXIT_SUCCESS; }
TEST_F(EventsDatabaseTests, test_record_indexing) { auto sub = std::make_shared<FakeEventSubscriber>(); auto status = sub->testAdd(2); status = sub->testAdd(11); status = sub->testAdd(61); status = sub->testAdd((1 * 3600) + 1); status = sub->testAdd((2 * 3600) + 1); // An "all" range, will pick up everything in the largest index. auto indexes = sub->getIndexes(0, 3 * 3600); auto output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "3600.0, 3600.1, 3600.2"); // Restrict range to "most specific". indexes = sub->getIndexes(0, 5); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "10.0"); // Get a mix of indexes for the lower bounding. indexes = sub->getIndexes(2, (3 * 3600)); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "3600.1, 3600.2, 60.1, 10.0, 10.1"); // Rare, but test ONLY intermediate indexes. indexes = sub->getIndexes(2, (3 * 3600), 1); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "60.0, 60.1, 60.60, 60.120"); // Add specific indexes to the upper bound. status = sub->testAdd((2 * 3600) + 11); status = sub->testAdd((2 * 3600) + 61); indexes = sub->getIndexes(2 * 3600, (2 * 3600) + 62); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "60.120, 10.726"); // Request specific lower and upper bounding. indexes = sub->getIndexes(2, (2 * 3600) + 62); output = boost::algorithm::join(indexes, ", "); EXPECT_EQ(output, "3600.1, 60.1, 60.120, 10.0, 10.1, 10.726"); }
TEST_F(EventsDatabaseTests, test_optimize) { auto sub = std::make_shared<DBFakeEventSubscriber>(); for (size_t i = 800; i < 800 + 10; ++i) { sub->testAdd(i); } // Lie about the tool type to enable optimizations. auto default_type = kToolType; kToolType = ToolType::DAEMON; FLAGS_events_optimize = true; // Must also define an executing query. setDatabaseValue(kPersistentSettings, kExecutingQuery, "events_db_test"); auto t = getUnixTime(); auto results = genRows(sub.get()); EXPECT_EQ(10U, results.size()); // Optimization will set the time NOW as the minimum event time. // Thus it is not possible to set event in past. EXPECT_GE(sub->optimize_time_ + 100, t); EXPECT_LE(sub->optimize_time_ - 100, t); // The last EID returned will also be stored for duplication checks. EXPECT_EQ(10U, sub->optimize_eid_); for (size_t i = t + 800; i < t + 800 + 10; ++i) { sub->testAdd(i); } results = genRows(sub.get()); EXPECT_EQ(10U, results.size()); // The optimize time should have been written to the database. // It should be the same as the current (relative) optimize time. std::string content; getDatabaseValue("events", "optimize.events_db_test", content); EXPECT_EQ(std::to_string(sub->optimize_time_), content); // Restore the tool type. kToolType = default_type; }
TEST_F(EventsDatabaseTests, test_record_expiration) { auto sub = std::make_shared<DBFakeEventSubscriber>(); auto status = sub->testAdd(1); status = sub->testAdd(2); status = sub->testAdd(11); status = sub->testAdd(61); status = sub->testAdd((1 * 3600) + 1); status = sub->testAdd((2 * 3600) + 1); // No expiration auto indexes = sub->getIndexes(0, 5000); auto records = sub->getRecords(indexes); EXPECT_EQ(5U, records.size()); // 1, 2, 11, 61, 3601 sub->expire_events_ = true; sub->expire_time_ = 10; indexes = sub->getIndexes(0, 5000); records = sub->getRecords(indexes); EXPECT_EQ(3U, records.size()); // 11, 61, 3601 indexes = sub->getIndexes(0, 5000); records = sub->getRecords(indexes); EXPECT_EQ(3U, records.size()); // 11, 61, 3601 indexes = sub->getIndexes(0, 5000); records = sub->getRecords(indexes); EXPECT_EQ(3U, records.size()); // 11, 61, 3601 indexes = sub->getIndexes(0, 5000); records = sub->getRecords(indexes); EXPECT_EQ(3U, records.size()); // 11, 61, 3601 // Check that get/deletes did not act on cache. // This implies that RocksDB is flushing the requested delete records. sub->expire_time_ = 0; indexes = sub->getIndexes(0, 5000); records = sub->getRecords(indexes); EXPECT_EQ(3U, records.size()); // 11, 61, 3601 }
TEST(ARingQQGMP, arithmetic) { M2::ARingQQGMP R; testCoercions(R); testNegate(R, ntrials); testAdd(R, ntrials); testSubtract(R, ntrials); testMultiply(R, ntrials); testDivide(R, ntrials); testReciprocal(R, ntrials); // testPower(R, ntrials); // this test can't work, as it expects a finite field testAxioms(R, ntrials); }
TEST(ARingZZ, arithmetic) { M2::ARingZZ R; testCoercions(R); testNegate(R, ntrials); testAdd(R, ntrials); testSubtract(R, ntrials); testMultiply(R, ntrials); testDivide(R, ntrials); // testReciprocal(R, ntrials); // this test is not applicable, as this is not // a field // testPower(R, ntrials); // this test can't work, as it expects a finite // field testAxioms(R, ntrials); }
void testFiniteField(const T& R, int ntrials) { testCoercions(R); testNegate(R, ntrials); testAdd(R, ntrials); //fails in char 2, ffpack (negating 1 gives -1)... testSubtract(R, ntrials); //fails in char 2, ffpack testMultiply(R, ntrials); testDivide(R, ntrials); //fails in char 2, ffpack testReciprocal(R, ntrials); testPower(R, ntrials);// fails? testAxioms(R, ntrials); //TODO: test promote, lift, syzygy(?), (ringmaps) // test random number generation? // get generator }
// TODO: commented out because it takes too long: // Actually: now this characteristic seems too big?! TEST(ARingZZpFFPACK, arithmetic67108859) { M2::ARingZZpFFPACK R(67108859); testCoerceToLongInteger(R); testCoercions(R); testNegate(R, ntrials); testAdd(R, ntrials); testSubtract(R, ntrials); testMultiply(R, ntrials); testDivide(R, ntrials); testReciprocal(R, ntrials); testPower(R, ntrials); testAxioms(R, ntrials); }
TEST(ARingZZpFlint, arithmetic33500479) { M2::ARingZZpFlint R(33500479); testCoerceToLongInteger(R); testCoercions(R); testNegate(R, ntrials); testAdd(R, ntrials); testSubtract(R, ntrials); testMultiply(R, ntrials); testDivide(R, ntrials); testReciprocal(R, ntrials); testPower(R, ntrials); testAxioms(R, ntrials); }
TEST_F(EventsDatabaseTests, test_gentable) { auto sub = std::make_shared<DBFakeEventSubscriber>(); auto status = sub->testAdd(1); status = sub->testAdd(2); status = sub->testAdd(11); status = sub->testAdd(61); status = sub->testAdd((1 * 3600) + 1); status = sub->testAdd((2 * 3600) + 1); ASSERT_EQ(0U, sub->optimize_time_); ASSERT_EQ(0U, sub->expire_time_); ASSERT_EQ(0U, sub->min_expiration_); auto t = getUnixTime(); sub->testAdd(t - 1); sub->testAdd(t); sub->testAdd(t + 1); // Test the expire workflow by creating a short expiration time. sub->setEventsExpiry(10); std::vector<std::string> keys; scanDatabaseKeys("events", keys); // 9 data records, 1 eid counter, 3 indexes, 15 index records. // Depending on the moment, an additional 3 indexes may be introduced. EXPECT_LE(16U, keys.size()); // Perform a "select" equivalent. auto results = genRows(sub.get()); // Expect all non-expired results: 11, + EXPECT_EQ(9U, results.size()); // The expiration time is now - events_expiry +/ 60. EXPECT_LT(t - (sub->getEventsExpiry() * 2), sub->expire_time_ + 60); EXPECT_GT(t, sub->expire_time_); // The optimize time will not be changed. ASSERT_EQ(0U, sub->optimize_time_); results = genRows(sub.get()); EXPECT_EQ(3U, results.size()); results = genRows(sub.get()); EXPECT_EQ(3U, results.size()); keys.clear(); scanDatabaseKeys("events", keys); EXPECT_LE(6U, keys.size()); }
void montgomery_array_tests(int bigtests) { // Sub function tests. testShiftRight(); testAdd(); testSub(); test_montgomery_one_item_array(); test_montgomery_modulus(); // modexp tests. test_montgomery_modexp(); // Fairly big. test_modExp_4096bit_e65537(); test_modExp_8192_e65537(); // Bigtests. if (bigtests) { test_modExp_8192bit(); } }
// Even though flint handles primes up to 2^64-1, M2 assumes that the // characteristic is < 2^63. If needed, we could change the type of // the characteristic to unsigned long, but that would have further // complications. TEST(ARingZZpFlint, arithmetic18446744073709551557) { // largest prime < 2^64 if (sizeof(unsigned long) <= 4) std::cout << "seems to be a 32bit machine: skipping the test" << std::endl; else { M2::ARingZZpFlint R(18446744073709551557UL); // testCoerceToLongInteger(R); // this fails for charac > 2^63 testCoercions(R); testNegate(R, ntrials); testAdd(R, ntrials); testSubtract(R, ntrials); testMultiply(R, ntrials); testDivide(R, ntrials); testReciprocal(R, ntrials); // testPower(R, ntrials); // this test fails: as it expects the // characteristic to fit into an int. testAxioms(R, ntrials); } }
/** * Invoke test functions */ void testAll() { testCreatePet(); testAdd(); testRepo(); testController(); }
void BasePerformanceTest::realTest(int i) { testAdd(i); testMove(i); testLeave(i); }
TEST_F(EventsDatabaseTests, test_event_add) { auto sub = std::make_shared<DBFakeEventSubscriber>(); auto status = sub->testAdd(1); EXPECT_TRUE(status.ok()); }