/* ================== CL_ParsePacketEntities ================== */ void CL_ParsePacketEntities( msg_t *msg, const clSnapshot_t *oldSnapshot, clSnapshot_t *newSnapshot ) { // The entity packet contains the delta between the two snapshots, with data only // for entities that were created, changed or removed. Entities entries are in // order of increasing entity number, as are entities in a snapshot. Using this we // have an efficient algorithm to create the new snapshot, that goes over the old // snapshot once from the beginning to the end. // If we don't have an old snapshot or it is empty, we'll recreate all entities // from the baseline entities as setting oldEntityNum to MAX_GENTITIES will force // us to only do step (3) below. unsigned int oldEntityNum = MAX_GENTITIES; if (oldSnapshot && oldSnapshot->entities.size() > 0){ oldEntityNum = oldSnapshot->entities[0].number; } // Likewise when we don't have an old snapshot, oldEntities just has to be an empty // vector so that we skip step (4) std::vector<entityState_t> dummyEntities; auto& oldEntities = oldSnapshot? oldSnapshot->entities : dummyEntities; auto& newEntities = newSnapshot->entities; unsigned int numEntities = MSG_ReadShort(msg); newEntities.reserve(numEntities); unsigned oldIndex = 0; while (true) { unsigned int newEntityNum = MSG_ReadBits(msg, GENTITYNUM_BITS); if (msg->readcount > msg->cursize) { Sys::Drop("CL_ParsePacketEntities: Unexpected end of message"); } if (newEntityNum == MAX_GENTITIES - 1) { break; } // (1) all entities that weren't specified between the previous newEntityNum and // the current one are unchanged and just copied over. while (oldEntityNum < newEntityNum) { newEntities.push_back(oldEntities[oldIndex]); oldIndex ++; if (oldIndex >= oldEntities.size()) { oldEntityNum = MAX_GENTITIES; } else { oldEntityNum = oldEntities[oldIndex].number; } } // (2) there is an entry for an entity in the old snapshot, apply the delta if (oldEntityNum == newEntityNum) { CL_DeltaEntity(msg, newSnapshot, newEntityNum, oldEntities[oldIndex]); oldIndex ++; if (oldIndex >= oldEntities.size()) { oldEntityNum = MAX_GENTITIES; } else { oldEntityNum = oldEntities[oldIndex].number; } } else { // (3) the entry isn't in the old snapshot, so the entity will be specified // from the baseline ASSERT_GT(oldEntityNum, newEntityNum); CL_DeltaEntity(msg, newSnapshot, newEntityNum, cl.entityBaselines[newEntityNum]); } } // (4) All remaining entities in the oldSnapshot are unchanged and copied over while (oldIndex < oldEntities.size()) { newEntities.push_back(oldEntities[oldIndex]); oldIndex ++; } ASSERT_EQ(numEntities, newEntities.size()); }
TEST(pcmtest, CheckAudioDir) { pcms = getPcmNodes(); ASSERT_GT(pcms, 0U); }
TEST(ParserTest, testParse) { try { ParsedQuery pq = SparqlParser::parse("SELECT ?x WHERE {?x ?y ?z}"); ASSERT_GT(pq.asString().size(), 0); ASSERT_EQ(0, pq._prefixes.size()); ASSERT_EQ(1, pq._selectedVariables.size()); ASSERT_EQ(1, pq._whereClauseTriples.size()); pq = SparqlParser::parse( "PREFIX : <http://rdf.myprefix.com/>\n" "PREFIX ns: <http://rdf.myprefix.com/ns/>\n" "PREFIX xxx: <http://rdf.myprefix.com/xxx/>\n" "SELECT ?x ?z \n " "WHERE \t {?x :myrel ?y. ?y ns:myrel ?z.?y nsx:rel2 <http://abc.de>}"); ASSERT_EQ(3, pq._prefixes.size()); ASSERT_EQ(2, pq._selectedVariables.size()); ASSERT_EQ(3, pq._whereClauseTriples.size()); ASSERT_EQ("", pq._prefixes[0]._prefix); ASSERT_EQ("<http://rdf.myprefix.com/>", pq._prefixes[0]._uri); ASSERT_EQ("ns", pq._prefixes[1]._prefix); ASSERT_EQ("<http://rdf.myprefix.com/ns/>", pq._prefixes[1]._uri); ASSERT_EQ("?x", pq._selectedVariables[0]); ASSERT_EQ("?z", pq._selectedVariables[1]); ASSERT_EQ("?x", pq._whereClauseTriples[0]._s); ASSERT_EQ(":myrel", pq._whereClauseTriples[0]._p); ASSERT_EQ("?y", pq._whereClauseTriples[0]._o); ASSERT_EQ("?y", pq._whereClauseTriples[1]._s); ASSERT_EQ("ns:myrel", pq._whereClauseTriples[1]._p); ASSERT_EQ("?z", pq._whereClauseTriples[1]._o); ASSERT_EQ("?y", pq._whereClauseTriples[2]._s); ASSERT_EQ("nsx:rel2", pq._whereClauseTriples[2]._p); ASSERT_EQ("<http://abc.de>", pq._whereClauseTriples[2]._o); ASSERT_EQ("", pq._limit); ASSERT_EQ("", pq._offset); pq = SparqlParser::parse( "PREFIX : <http://rdf.myprefix.com/>\n" "PREFIX ns: <http://rdf.myprefix.com/ns/>\n" "PREFIX xxx: <http://rdf.myprefix.com/xxx/>\n" "SELECT ?x ?z \n " "WHERE \t {\n?x :myrel ?y. ?y ns:myrel ?z.\n?y nsx:rel2 <http://abc.de>\n}"); ASSERT_EQ(3, pq._prefixes.size()); ASSERT_EQ(2, pq._selectedVariables.size()); ASSERT_EQ(3, pq._whereClauseTriples.size()); ASSERT_EQ("", pq._prefixes[0]._prefix); ASSERT_EQ("<http://rdf.myprefix.com/>", pq._prefixes[0]._uri); ASSERT_EQ("ns", pq._prefixes[1]._prefix); ASSERT_EQ("<http://rdf.myprefix.com/ns/>", pq._prefixes[1]._uri); ASSERT_EQ("?x", pq._selectedVariables[0]); ASSERT_EQ("?z", pq._selectedVariables[1]); ASSERT_EQ("?x", pq._whereClauseTriples[0]._s); ASSERT_EQ(":myrel", pq._whereClauseTriples[0]._p); ASSERT_EQ("?y", pq._whereClauseTriples[0]._o); ASSERT_EQ("?y", pq._whereClauseTriples[1]._s); ASSERT_EQ("ns:myrel", pq._whereClauseTriples[1]._p); ASSERT_EQ("?z", pq._whereClauseTriples[1]._o); ASSERT_EQ("?y", pq._whereClauseTriples[2]._s); ASSERT_EQ("nsx:rel2", pq._whereClauseTriples[2]._p); ASSERT_EQ("<http://abc.de>", pq._whereClauseTriples[2]._o); ASSERT_EQ("", pq._limit); ASSERT_EQ("", pq._offset); pq = SparqlParser::parse( "PREFIX ns: <http://ns/>" "SELECT ?x ?z \n " "WHERE \t {\n?x <Directed_by> ?y. ?y ns:myrel.extend ?z.\n" "?y nsx:rel2 \"Hello... World\"}"); ASSERT_EQ(1, pq._prefixes.size()); ASSERT_EQ(2, pq._selectedVariables.size()); ASSERT_EQ(3, pq._whereClauseTriples.size()); pq.expandPrefixes(); ASSERT_EQ("?x", pq._selectedVariables[0]); ASSERT_EQ("?z", pq._selectedVariables[1]); ASSERT_EQ("?x", pq._whereClauseTriples[0]._s); ASSERT_EQ("<Directed_by>", pq._whereClauseTriples[0]._p); ASSERT_EQ("?y", pq._whereClauseTriples[0]._o); ASSERT_EQ("?y", pq._whereClauseTriples[1]._s); ASSERT_EQ("<http://ns/myrel.extend>", pq._whereClauseTriples[1]._p); ASSERT_EQ("?z", pq._whereClauseTriples[1]._o); ASSERT_EQ("?y", pq._whereClauseTriples[2]._s); ASSERT_EQ("nsx:rel2", pq._whereClauseTriples[2]._p); ASSERT_EQ("\"Hello... World\"", pq._whereClauseTriples[2]._o); ASSERT_EQ("", pq._limit); ASSERT_EQ("", pq._offset); pq = SparqlParser::parse( "SELECT ?x ?y WHERE {?x is-a Actor . FILTER(?x != ?y)." "?y is-a Actor . FILTER(?y < ?x)} LIMIT 10"); pq.expandPrefixes(); ASSERT_EQ(2, pq._filters.size()); ASSERT_EQ("?x", pq._filters[0]._lhs); ASSERT_EQ("?y", pq._filters[0]._rhs); ASSERT_EQ(SparqlFilter::FilterType::NE, pq._filters[0]._type); ASSERT_EQ("?y", pq._filters[1]._lhs); ASSERT_EQ("?x", pq._filters[1]._rhs); ASSERT_EQ(SparqlFilter::FilterType::LT, pq._filters[1]._type); ASSERT_EQ(2, pq._whereClauseTriples.size()); pq = SparqlParser::parse( "SELECT ?x ?y WHERE {?x is-a Actor . FILTER(?x != ?y)." "?y is-a Actor} LIMIT 10"); pq.expandPrefixes(); ASSERT_EQ(1, pq._filters.size()); ASSERT_EQ("?x", pq._filters[0]._lhs); ASSERT_EQ("?y", pq._filters[0]._rhs); ASSERT_EQ(SparqlFilter::FilterType::NE, pq._filters[0]._type); ASSERT_EQ(2, pq._whereClauseTriples.size()); pq = SparqlParser::parse( "SELECT ?x ?y WHERE {?x is-a Actor . FILTER(?x != ?y)." "?y is-a Actor. ?x <in-context> ?c." "?c <in-context> coca* abuse} LIMIT 10"); pq.expandPrefixes(); ASSERT_EQ(1, pq._filters.size()); ASSERT_EQ("?x", pq._filters[0]._lhs); ASSERT_EQ("?y", pq._filters[0]._rhs); ASSERT_EQ(SparqlFilter::FilterType::NE, pq._filters[0]._type); ASSERT_EQ(4, pq._whereClauseTriples.size()); ASSERT_EQ("?x", pq._whereClauseTriples[2]._s); ASSERT_EQ("<in-context>", pq._whereClauseTriples[2]._p); ASSERT_EQ("?c", pq._whereClauseTriples[2]._o); ASSERT_EQ("?c", pq._whereClauseTriples[3]._s); ASSERT_EQ("<in-context>", pq._whereClauseTriples[3]._p); ASSERT_EQ("coca* abuse", pq._whereClauseTriples[3]._o); pq = SparqlParser::parse( "PREFIX : <>\n" "SELECT ?x ?y ?z TEXT(?c) SCORE(?c) ?c WHERE {\n" "?x :is-a :Politician .\n" "?x :in-context ?c .\n" "?c :in-context friend .\n" "?c :in-context ?y .\n" "?y :is-a :Scientist .\n" "FILTER(?x != ?y) .\n" "} ORDER BY ?c"); pq.expandPrefixes(); ASSERT_EQ(1, pq._filters.size()); } catch (const ad_semsearch::Exception& e) { FAIL() << e.getFullErrorMessage(); } };
int main() { try { bool CLUSTER_MODE = false; boost::shared_ptr<redis::client> shared_c; if(CLUSTER_MODE) shared_c = init_cluster_client(); else shared_c = init_non_cluster_client(); redis::client & c = *shared_c; // Test on high number databases c.select(14); c.flushdb(); ASSERT_EQUAL(c.dbsize(), (redis::client::int_type) 0); c.select(15); c.flushdb(); ASSERT_EQUAL(c.dbsize(), (redis::client::int_type) 0); string foo("foo"), bar("bar"), baz("baz"), buz("buz"), goo("goo"); test("auth"); { // TODO ... needs a conf for redis-server } test("binary save values"); { int repeations = 3; string bin; for(int i=0; i < repeations; i++) { for(int i1=0; i1 <= 255; i1++) bin += (char) i1; } c.set("binary", bin); string response = c.get("binary"); ASSERT_EQUAL(response.size(), (size_t)repeations*256); ASSERT_EQUAL(response, bin); c.append("binary", bin); ASSERT_EQUAL(c.get("binary"), bin+bin); string second_half = c.substr("binary", bin.size(), -1); ASSERT_EQUAL(second_half, bin); } test("binary save keys"); { string bin1 = "bin_"; for(int i1=0; i1 <= 127; i1++) bin1 += (char) i1; ASSERT_EQUAL(c.exists(bin1), false); c.set(bin1, "hello world"); ASSERT_EQUAL(c.exists(bin1), true); ASSERT_EQUAL(c.get(bin1), string("hello world")); string bin2 = "bin_"; for(int i1=128; i1 <= 255; i1++) bin2 += (char) i1; ASSERT_EQUAL(c.exists(bin2), false); c.set(bin2, "hello world"); ASSERT_EQUAL(c.exists(bin2), true); ASSERT_EQUAL(c.get(bin2), string("hello world")); redis::client::string_vector keys; redis::client::int_type count = c.keys("bin_*", keys); ASSERT_EQUAL(count, (redis::client::int_type) 2); ASSERT_EQUAL(keys.size(), (size_t) 2); if( keys[0] == bin1 ) ASSERT_EQUAL(keys[1], bin2); else if( keys[0] == bin2 ) ASSERT_EQUAL(keys[1], bin1); else // keys[0] must be bin1 or bin2 so we must fail here ASSERT_EQUAL(true, false); } redis::server_info info; test("info"); { // doesn't throw? then, has valid numbers and known info-keys. c.info(info); } test("set, get"); { c.set(foo, bar); ASSERT_EQUAL(c.get(foo), bar); } test("getset"); { ASSERT_EQUAL(c.getset(foo, baz), bar); ASSERT_EQUAL(c.get(foo), baz); } test("mget"); { string x_val("hello"), y_val("world"); c.set("x", x_val); c.set("y", y_val); redis::client::string_vector keys; keys.push_back("x"); keys.push_back("y"); redis::client::string_vector vals; c.mget(keys, vals); ASSERT_EQUAL(vals.size(), size_t(2)); ASSERT_EQUAL(vals[0], x_val); ASSERT_EQUAL(vals[1], y_val); } test("setnx"); { ASSERT_EQUAL(c.setnx(foo, bar), false); ASSERT_EQUAL(c.setnx(buz, baz), true); ASSERT_EQUAL(c.get(buz), baz); } test("incr"); { ASSERT_EQUAL(c.incr("goo"), 1L);test("nonexistent (0) -> 1"); ASSERT_EQUAL(c.incr("goo"), 2L);test("1->2"); } test("decr"); { ASSERT_EQUAL(c.decr("goo"), 1L);test("2->1"); ASSERT_EQUAL(c.decr("goo"), 0L);test("1->0"); } test("incrby"); { ASSERT_EQUAL(c.incrby("goo", 3L), 3L);test("0->3"); ASSERT_EQUAL(c.incrby("goo", 2L), 5L);test("3->5"); } test("exists"); { ASSERT_EQUAL(c.exists("goo"), true); } test("del"); { c.del("goo"); ASSERT_EQUAL(c.exists("goo"), false); } test("type (basic)"); { ASSERT_EQUAL(c.type(goo), redis::client::datatype_none);test("we deleted it"); c.set(goo, "redis"); ASSERT_EQUAL(c.type(goo), redis::client::datatype_string); } test("keys"); { redis::client::string_vector keys; ASSERT_EQUAL(c.keys("*oo", keys), 2L); ASSERT_EQUAL(keys.size(), (size_t) 2); ASSERT_EQUAL(keys[0], foo); ASSERT_EQUAL(keys[1], goo); } test("randomkey"); { ASSERT_GT(c.randomkey().size(), (size_t) 0); } test("rename"); { ASSERT_EQUAL(c.exists("foo"), true); ASSERT_EQUAL(c.exists("doo"), false); c.rename("foo", "doo"); ASSERT_EQUAL(c.exists("foo"), false); ASSERT_EQUAL(c.exists("doo"), true); } test("renamenx"); { ASSERT_EQUAL(c.exists("doo"), true); ASSERT_EQUAL(c.exists("foo"), false); ASSERT_EQUAL(c.renamenx("doo", "foo"), true); ASSERT_EQUAL(c.exists("doo"), false); ASSERT_EQUAL(c.exists("foo"), true); ASSERT_EQUAL(c.renamenx("goo", "foo"), false); ASSERT_EQUAL(c.exists("foo"), true); ASSERT_EQUAL(c.exists("goo"), true); } test("dbsize"); { ASSERT_GT(c.dbsize(), 0L); } test("expire"); { c.expire("goo", 1); #ifndef NDEBUG cerr << "please wait a few seconds.." << endl; #endif sleep(2); ASSERT_EQUAL(c.exists("goo"), false); } test("move"); { c.select(14); ASSERT_EQUAL(c.exists("ttt"), false); c.select(15); c.set("ttt", "uuu"); c.move("ttt", 14); c.select(14); ASSERT_EQUAL(c.exists("ttt"), true); c.select(15); ASSERT_EQUAL(c.exists("ttt"), false); } test("move should fail since key exists already"); { c.select(14); c.set("ttt", "xxx"); c.select(15); c.set("ttt", "uuu"); bool threw = false; try { c.move("ttt", 14); } catch (redis::protocol_error & e) { threw = true; } ASSERT_EQUAL(threw, true); c.select(14); ASSERT_EQUAL(c.exists("ttt"), true); c.select(15); ASSERT_EQUAL(c.exists("ttt"), true); } test("sort ascending"); { c.sadd("sort1", "3"); c.sadd("sort1", "2"); c.sadd("sort1", "1"); redis::client::string_vector sorted; ASSERT_EQUAL(c.sort("sort1", sorted), 3L); ASSERT_EQUAL(sorted.size(), (size_t) 3); ASSERT_EQUAL(sorted[0], string("1")); ASSERT_EQUAL(sorted[1], string("2")); ASSERT_EQUAL(sorted[2], string("3")); } test("sort descending"); { redis::client::string_vector sorted; ASSERT_EQUAL(c.sort("sort1", sorted, redis::client::sort_order_descending), 3L); ASSERT_EQUAL(sorted.size(), (size_t) 3); ASSERT_EQUAL(sorted[0], string("3")); ASSERT_EQUAL(sorted[1], string("2")); ASSERT_EQUAL(sorted[2], string("1")); } test("sort with limit"); { // TODO } test("sort lexicographically"); { // TODO } test("sort with pattern and weights"); { // TODO } test_lists(c); test_sets(c); test_zsets(c); test_hashes(c); test_distributed_strings(c); test_distributed_ints(c); //test_distributed_mutexes(c); test_generic(c); test_pubsub(c); benchmark(c, 10000); test("save"); { c.save(); } test("bgsave"); { c.bgsave(); } test("lastsave"); { ASSERT_GT(c.lastsave(), 0L); } test("shutdown"); { // You can test this if you really want to ... // c.shutdown(); } } catch (redis::redis_error & e) { cerr << "got exception: " << e.what() << endl << "FAIL" << endl; return 1; } cout << endl << "testing completed successfully" << endl; return 0; }
#include "illuminate.hpp" TEST_CASE(ASSERT_LT) { ASSERT_GT(1+1,2+2) ASSERT_GT(2+2,2+2) ASSERT_GT(2+2,1+1) }
TEST(PlanningInterfaceTester, loadAllPlanners) { pluginlib::ClassLoader<planning_interface::Planner>* planner_loader; try { planner_loader = new pluginlib::ClassLoader<planning_interface::Planner>("planning_interface", "planning_interface::Planner"); } catch(pluginlib::PluginlibException& ex) { FAIL() << "Exception while creating class loader " << ex.what(); } std::vector<std::string> classes; std::vector<boost::shared_ptr<planning_interface::Planner> > planners; planning_scene::PlanningSceneConstPtr scene = g_psm->getPlanningScene(); planning_models::RobotModelConstPtr model = scene->getRobotModel(); classes = planner_loader->getDeclaredClasses(); // Must have some planners ASSERT_GT(classes.size(), 0); printf("Loading classes:\n"); for(std::vector<std::string>::const_iterator it = classes.begin(); it != classes.end(); ++it) printf(" %s\n", it->c_str()); fflush(stdout); return; for(std::vector<std::string>::const_iterator it = classes.begin(); it != classes.end(); ++it) { try { boost::shared_ptr<planning_interface::Planner> p(planner_loader->createUnmanagedInstance(*it)); p->init(model); planners.push_back(p); } catch(pluginlib::PluginlibException& ex) { // All planners must load ADD_FAILURE() << "Exception while loading planner: " << *it << ": " << ex.what(); } } for(std::vector<boost::shared_ptr<planning_interface::Planner> >::const_iterator it = planners.begin(); it != planners.end(); ++it) { // A dumb test: require that the planners return true from // canServiceRequest moveit_msgs::GetMotionPlan::Request req; planning_interface::PlannerCapability capabilities; bool can_service = (*it)->canServiceRequest(req, capabilities); EXPECT_TRUE(can_service); // Another dumb test: require that the planners return false from solve moveit_msgs::GetMotionPlan::Response res; bool solved = (*it)->solve(scene, req, res); EXPECT_FALSE(solved); } }
// Verifies that CachedResources are evicted from the decode cache // according to their DecodeCachePriority. TEST_F(MemoryCacheTest, DecodeCacheOrder) { memoryCache()->setDelayBeforeLiveDecodedPrune(0); ResourcePtr<MockImageResource> cachedImageLowPriority = new MockImageResource(ResourceRequest(""), Resource::Raw); ResourcePtr<MockImageResource> cachedImageHighPriority = new MockImageResource(ResourceRequest(""), Resource::Raw); MockImageResourceClient clientLowPriority; MockImageResourceClient clientHighPriority; cachedImageLowPriority->addClient(&clientLowPriority); cachedImageHighPriority->addClient(&clientHighPriority); const char data[5] = "abcd"; cachedImageLowPriority->appendData(data, 1); cachedImageHighPriority->appendData(data, 4); const unsigned lowPrioritySize = cachedImageLowPriority->size(); const unsigned highPrioritySize = cachedImageHighPriority->size(); const unsigned lowPriorityMockDecodeSize = cachedImageLowPriority->decodedSize(); const unsigned highPriorityMockDecodeSize = cachedImageHighPriority->decodedSize(); const unsigned totalSize = lowPrioritySize + highPrioritySize; // Verify that the sizes are different to ensure that we can test eviction order. ASSERT_GT(lowPrioritySize, 0u); ASSERT_NE(lowPrioritySize, highPrioritySize); ASSERT_GT(lowPriorityMockDecodeSize, 0u); ASSERT_NE(lowPriorityMockDecodeSize, highPriorityMockDecodeSize); ASSERT_EQ(memoryCache()->deadSize(), 0u); ASSERT_EQ(memoryCache()->liveSize(), 0u); // Add the items. The item added first would normally be evicted first. memoryCache()->add(cachedImageHighPriority.get()); ASSERT_EQ(memoryCache()->deadSize(), 0u); ASSERT_EQ(memoryCache()->liveSize(), highPrioritySize); memoryCache()->add(cachedImageLowPriority.get()); ASSERT_EQ(memoryCache()->deadSize(), 0u); ASSERT_EQ(memoryCache()->liveSize(), highPrioritySize + lowPrioritySize); // Insert all items in the decoded items list with the same priority memoryCache()->insertInLiveDecodedResourcesList(cachedImageHighPriority.get()); memoryCache()->insertInLiveDecodedResourcesList(cachedImageLowPriority.get()); ASSERT_EQ(memoryCache()->deadSize(), 0u); ASSERT_EQ(memoryCache()->liveSize(), totalSize); // Now we will assign their priority and make sure they are moved to the correct buckets. cachedImageLowPriority->setCacheLiveResourcePriority(Resource::CacheLiveResourcePriorityLow); cachedImageHighPriority->setCacheLiveResourcePriority(Resource::CacheLiveResourcePriorityHigh); // Should first prune the LowPriority item. memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache()->liveSize() - 10, memoryCache()->liveSize() - 10); memoryCache()->prune(); ASSERT_EQ(memoryCache()->deadSize(), 0u); ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize); // Should prune the HighPriority item. memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache()->liveSize() - 10, memoryCache()->liveSize() - 10); memoryCache()->prune(); ASSERT_EQ(memoryCache()->deadSize(), 0u); ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize - highPriorityMockDecodeSize); }
TEST(unistd, sysconf_SC_MONOTONIC_CLOCK) { ASSERT_GT(sysconf(_SC_MONOTONIC_CLOCK), 0); }
void f() { ASSERT_GT(m_numRefCalls, 0); }
void g(int) { ASSERT_GT(m_numRefCalls, 0); }
TEST_F(TestFileCache, WriteAndReadBack) { // Set up something for FileCache to read in. char data_fn[] = "/tmp/hhvm_unit_test-testdata.XXXXXX"; int data_fd = mkstemp(data_fn); ASSERT_GT(data_fd, 0); FILE* f = fdopen(data_fd, "w"); ASSERT_TRUE(f != nullptr); fprintf(f, "%s", kTestData); fclose(f); // Set up a cache and put this data file in it. FileCache fc; fc.write("_unit_test_one_", data_fn); fc.write("_unit_test_two_", false); fc.write("/__invalid__/path/with/directories", true); string temp_dir; ASSERT_TRUE(makeTempDir(&temp_dir)); string cache_fn(temp_dir); cache_fn.append("/cache.dump"); // Flush to disk. fc.save(cache_fn.c_str()); // Sniff around the on-disk temp file. FileCache ondisk; EXPECT_EQ(ondisk.getVersion(cache_fn.c_str()), 2); // Read back into another cache. FileCache fc2; fc2.loadMmap(cache_fn.c_str(), 1); EXPECT_TRUE(fc2.fileExists("_unit_test_one_")); int read_len; bool compressed = false; const char* read_data = fc2.read("_unit_test_one_", read_len, compressed); EXPECT_STREQ(kTestData, read_data); EXPECT_EQ(fc2.fileSize("_unit_test_one_", false), strlen(kTestData)); EXPECT_TRUE(fc2.fileExists("_unit_test_two_")); EXPECT_FALSE(fc2.fileExists("_unit_test_three_")); EXPECT_TRUE(fc2.dirExists("/__invalid__")); EXPECT_TRUE(fc2.dirExists("/__invalid__/path")); EXPECT_TRUE(fc2.dirExists("/__invalid__/path/with")); EXPECT_TRUE(fc2.fileExists("/__invalid__/path/with/directories")); // -1 is a magic value... here it means "it's a PHP file"... EXPECT_EQ(fc2.fileSize("unit_test_two_", false), -1); // ... and here it means "this thing does not exist". EXPECT_EQ(fc2.fileSize("unit_test_three_", false), -1); fc2.dump(); // Clean up the mess. ASSERT_EQ(unlink(cache_fn.c_str()), 0); ASSERT_EQ(rmdir(temp_dir.c_str()), 0); ASSERT_EQ(unlink(data_fn), 0); }
// As above, but using loadMmap instead (which doesn't do on-demand). TEST_F(TestFileCache, HighlyCompressibleDataMmapOLD) { FileCache::UseNewCache = false; char data_fn[] = "/tmp/hhvm_unit_test-testdata.XXXXXX"; int data_fd = mkstemp(data_fn); ASSERT_GT(data_fd, 0); FILE* f = fdopen(data_fd, "w"); ASSERT_TRUE(f != nullptr); string test_path = "/path/to/data"; string test_data; for (int i = 0; i < 10; ++i) { test_data.append("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); } fprintf(f, "%s", test_data.c_str()); fclose(f); FileCache fc; fc.write(test_path.c_str(), data_fn); // Flush to disk. char cache_fn[] = "/tmp/hhvm_unit_test.cache.XXXXXX"; close(mkstemp(cache_fn)); fc.save(cache_fn); // Read back into another cache (onDemandUncompress is not an option). FileCache fc2; fc2.loadMmap(cache_fn, 1); fc2.dump(); ASSERT_TRUE(fc2.fileExists(test_path.c_str())); int read_len; bool compressed = false; // "I want uncompressed data" const char* read_data = fc2.read(test_path.c_str(), read_len, compressed); // FileCache::read() takes compressed as a non-const reference (!) // and changes the value according to what it found... // This means "you just read a blob of compressed data"... EXPECT_TRUE(compressed); // ... so these can't match. EXPECT_NE(test_data, read_data); EXPECT_NE(test_data.length(), read_len); // But this always gets the uncompressed size no matter what. EXPECT_EQ(test_data.length(), fc2.fileSize(test_path.c_str(), false)); // So now let's actually ask for compressed data this time. compressed = true; read_data = fc2.read(test_path.c_str(), read_len, compressed); // Same conditions should hold. EXPECT_TRUE(compressed); EXPECT_NE(test_data, read_data); EXPECT_EQ(test_data.length(), fc2.fileSize(test_path.c_str(), false)); // Clean up the mess. ASSERT_EQ(unlink(cache_fn), 0); ASSERT_EQ(unlink(data_fn), 0); }
TEST_F(TestFileCache, HighlyCompressibleData) { char data_fn[] = "/tmp/hhvm_unit_test-testdata.XXXXXX"; int data_fd = mkstemp(data_fn); ASSERT_GT(data_fd, 0); FILE* f = fdopen(data_fd, "w"); ASSERT_TRUE(f != nullptr); string test_path = "/path/to/data"; string test_data; for (int i = 0; i < 10; ++i) { test_data.append("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); } fprintf(f, "%s", test_data.c_str()); fclose(f); FileCache fc; fc.write(test_path.c_str(), data_fn); // Flush to disk. string temp_dir; ASSERT_TRUE(makeTempDir(&temp_dir)); string cache_fn(temp_dir); cache_fn.append("/cache.dump"); fc.save(cache_fn.c_str()); // Read back into another cache. int read_len; bool compressed; const char* read_data; FileCache fc3; fc3.loadMmap(cache_fn.c_str(), 1); fc3.dump(); ASSERT_TRUE(fc3.fileExists(test_path.c_str())); // Ask for uncompressed data (a holdover from the original API). compressed = false; read_data = fc3.read(test_path.c_str(), read_len, compressed); // FileCache::read() takes compressed as a non-const reference (!) // and changes the value according to what it found... // ... so this means "I just gave you compressed data". EXPECT_TRUE(compressed); // ... so these can't match. EXPECT_NE(test_data, read_data); EXPECT_NE(test_data.length(), read_len); // But this always gets the uncompressed size no matter what. EXPECT_EQ(test_data.length(), fc3.fileSize(test_path.c_str(), false)); // So now let's actually ask for compressed data this time. compressed = true; read_data = fc3.read(test_path.c_str(), read_len, compressed); // Same conditions should hold. EXPECT_TRUE(compressed); EXPECT_NE(test_data, read_data); EXPECT_EQ(test_data.length(), fc3.fileSize(test_path.c_str(), false)); // Clean up the mess. ASSERT_EQ(unlink(cache_fn.c_str()), 0); ASSERT_EQ(rmdir(temp_dir.c_str()), 0); ASSERT_EQ(unlink(data_fn), 0); }
void Environment::SetUp() { uint32_t count; VkResult U_ASSERT_ONLY err; VkInstanceCreateInfo inst_info = {}; std::vector<VkExtensionProperties> instance_extensions; std::vector<VkExtensionProperties> device_extensions; std::vector<const char *> instance_extension_names; std::vector<const char *> device_extension_names; instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); #ifdef _WIN32 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); #endif #ifdef VK_USE_PLATFORM_XCB_KHR instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); #endif VkBool32 extFound; instance_extensions = vk_testing::GetGlobalExtensions(); for (uint32_t i = 0; i < instance_extension_names.size(); i++) { extFound = 0; for (uint32_t j = 0; j < instance_extensions.size(); j++) { if (!strcmp(instance_extension_names[i], instance_extensions[j].extensionName)) { extFound = 1; } } ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] << " which is necessary to pass this test"; } inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; inst_info.pNext = NULL; inst_info.pApplicationInfo = &app_; inst_info.enabledExtensionCount = instance_extension_names.size(); inst_info.ppEnabledExtensionNames = (instance_extension_names.size()) ? &instance_extension_names[0] : NULL; inst_info.enabledLayerCount = 0; inst_info.ppEnabledLayerNames = NULL; err = vkCreateInstance(&inst_info, NULL, &inst); ASSERT_EQ(VK_SUCCESS, err); err = vkEnumeratePhysicalDevices(inst, &count, NULL); ASSERT_EQ(VK_SUCCESS, err); ASSERT_LE(count, ARRAY_SIZE(gpus)); err = vkEnumeratePhysicalDevices(inst, &count, gpus); ASSERT_EQ(VK_SUCCESS, err); ASSERT_GT(count, default_dev_); vk_testing::PhysicalDevice phys_dev(gpus[0]); device_extensions = phys_dev.extensions(); for (uint32_t i = 0; i < device_extension_names.size(); i++) { extFound = 0; for (uint32_t j = 0; j < device_extensions.size(); j++) { if (!strcmp(device_extension_names[i], device_extensions[j].extensionName)) { extFound = 1; } } ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] << " which is necessary to pass this test"; } devs_.reserve(count); for (uint32_t i = 0; i < count; i++) { devs_.push_back(new Device(gpus[i])); if (i == default_dev_) { devs_[i]->init(device_extension_names); ASSERT_NE(true, devs_[i]->graphics_queues().empty()); } } }
/** * Tests whether it is possible to use multiple agents. */ TEST_F(AlicaMultiAgent, runMultiAgentPlan) { sc->setHostname("nase"); cace = Cace::getEmulated(sc->getHostname(), sc->getOwnRobotID()); cace->safeStepMode = true; ae = new alica::AlicaEngine(); ae->setIAlicaClock(new alicaCaceProxy::AlicaCaceClock(cace)); ae->setCommunicator(new alicaCaceProxy::AlicaCaceCommunication(ae, cace)); ASSERT_TRUE(ae->init(bc, cc, uc, crc, "RolesetTA", "MultiAgentTestMaster", ".", true)) << "Unable to initialise the Alica Engine!"; sc->setHostname("hairy"); cace2 = Cace::getEmulated(sc->getHostname(), sc->getOwnRobotID()); cace2->safeStepMode = true; ae2 = new alica::AlicaEngine(); ae2->setIAlicaClock(new alicaCaceProxy::AlicaCaceClock(cace2)); ae2->setCommunicator(new alicaCaceProxy::AlicaCaceCommunication(ae2, cace2)); ASSERT_TRUE(ae2->init(bc, cc, uc, crc, "RolesetTA", "MultiAgentTestMaster", ".", true)) << "Unable to initialise the Alica Engine!"; ae->start(); ae2->start(); for (int i = 0; i < 20; i++) { ae->stepNotify(); chrono::milliseconds duration(33); this_thread::sleep_for(duration); ae2->stepNotify(); this_thread::sleep_for(duration); // if (i > 24) // { // if (ae->getPlanBase()->getDeepestNode() != nullptr) // cout << "AE: " << ae->getPlanBase()->getDeepestNode()->toString() << endl; // if (ae2->getPlanBase()->getDeepestNode() != nullptr) // cout << "AE2: " << ae2->getPlanBase()->getDeepestNode()->toString() << endl; // cout << "-------------------------" << endl; // } if (i < 10) { ASSERT_EQ(ae->getPlanBase()->getRootNode()->getActiveState()->getId(), 1413200842974); ASSERT_EQ(ae2->getPlanBase()->getRootNode()->getActiveState()->getId(), 1413200842974); } if (i == 10) { cout << "1--------- Initial State passed ---------" << endl; alicaTests::TestWorldModel::getOne()->setTransitionCondition1413201227586(true); alicaTests::TestWorldModel::getTwo()->setTransitionCondition1413201227586(true); } if (i > 11 && i < 15) { ASSERT_EQ(ae->getPlanBase()->getRootNode()->getActiveState()->getId(), 1413201213955); ASSERT_EQ(ae2->getPlanBase()->getRootNode()->getActiveState()->getId(), 1413201213955); ASSERT_EQ((*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getPlan()->getName(), string("MultiAgentTestPlan")); ASSERT_EQ((*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getPlan()->getName(), string("MultiAgentTestPlan")); } if (i == 15) { for (auto iter : *ae->getBehaviourPool()->getAvailableBehaviours()) { if (iter.second->getName() == "Attack") { ASSERT_GT(((alicaTests::Attack* )&*iter.second)->callCounter, 5); if (((alicaTests::Attack*)&*iter.second)->callCounter > 3) { alicaTests::TestWorldModel::getOne()->setTransitionCondition1413201052549(true); alicaTests::TestWorldModel::getTwo()->setTransitionCondition1413201052549(true); alicaTests::TestWorldModel::getOne()->setTransitionCondition1413201370590(true); alicaTests::TestWorldModel::getTwo()->setTransitionCondition1413201370590(true); } } } cout << "2--------- Engagement to cooperative plan passed ---------" << endl; } if (i == 16) { ASSERT_TRUE( (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413201030936 || (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413201030936) << endl << (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << " " << (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << endl; ASSERT_TRUE( (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413807264574 || (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413807264574) << endl << (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << " " << (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << endl; alicaTests::TestWorldModel::getOne()->setTransitionCondition1413201227586(false); alicaTests::TestWorldModel::getTwo()->setTransitionCondition1413201227586(false); cout << "3--------- Passed transitions in subplan passed ---------" << endl; } if (i >= 17 && i <= 18) { ASSERT_TRUE( (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413201030936 || (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413201030936) << "AE State: " << (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << " AE2 State: " << (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << endl; ASSERT_TRUE( (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413807264574 || (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413807264574) << "AE State: " << (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << " " << (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->toString() << endl << " AE2 State: " << (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << " " << (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->toString() << endl; if(i==18) { cout << "4--------- Stayed in these state although previous transitions are not true anymore ---------" << endl; alicaTests::TestWorldModel::getOne()->setTransitionCondition1413201389955(true); alicaTests::TestWorldModel::getTwo()->setTransitionCondition1413201389955(true); } } if (i == 19) { ASSERT_TRUE( ae2->getPlanBase()->getRootNode()->getActiveState()->getId() == 1413201380359 && ae->getPlanBase()->getRootNode()->getActiveState()->getId() == 1413201380359) << " AE State: " << ae->getPlanBase()->getRootNode()->getActiveState()->getId() << " AE2 State: " << ae2->getPlanBase()->getRootNode()->getActiveState()->getId() << endl; } } }