From 0d009a4e980e40dc8a9c9b5e3d25c3fafb363e95 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 7 Jan 2010 21:27:39 +0000 Subject: Move unit testing and coverage framework into autowaf. Make raul tests return 0 on success, 1 on failure. Test coverage for Raul. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@2368 a436a847-0d15-0410-975c-d299462d15a1 --- tests/atomic_test.cpp | 14 -- tests/list_test.cpp | 168 ------------------ tests/midi_ringbuffer_test.cpp | 46 ----- tests/path_test.cpp | 46 ----- tests/quantize_test.cpp | 31 ---- tests/queue_test.cpp | 278 ----------------------------- tests/ringbuffer_test.cpp | 47 ----- tests/smf_test.cpp | 62 ------- tests/table_test.cpp | 384 ----------------------------------------- tests/thread_test.cpp | 19 -- tests/time_test.cpp | 32 ---- tests/wscript | 25 --- 12 files changed, 1152 deletions(-) delete mode 100644 tests/atomic_test.cpp delete mode 100644 tests/list_test.cpp delete mode 100644 tests/midi_ringbuffer_test.cpp delete mode 100644 tests/path_test.cpp delete mode 100644 tests/quantize_test.cpp delete mode 100644 tests/queue_test.cpp delete mode 100644 tests/ringbuffer_test.cpp delete mode 100644 tests/smf_test.cpp delete mode 100644 tests/table_test.cpp delete mode 100644 tests/thread_test.cpp delete mode 100644 tests/time_test.cpp delete mode 100644 tests/wscript (limited to 'tests') diff --git a/tests/atomic_test.cpp b/tests/atomic_test.cpp deleted file mode 100644 index 6611c91..0000000 --- a/tests/atomic_test.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "raul/AtomicInt.hpp" -#include "raul/AtomicPtr.hpp" - -using namespace std; -using namespace Raul; - -int -main() -{ - cout << "Well, at least I compiled; that's gotta count for something eh?" << endl; - - return 0; -} diff --git a/tests/list_test.cpp b/tests/list_test.cpp deleted file mode 100644 index ae139ce..0000000 --- a/tests/list_test.cpp +++ /dev/null @@ -1,168 +0,0 @@ -#include -#include -#include "raul/List.hpp" - -using namespace std; -using namespace Raul; - - -int main() -{ - List l; - - l.push_back(new List::Node(1)); - l.push_back(new List::Node(2)); - l.push_back(new List::Node(3)); - l.push_back(new List::Node(4)); - l.push_back(new List::Node(5)); - l.push_back(new List::Node(6)); - l.push_back(new List::Node(7)); - l.push_back(new List::Node(8)); - - cout << "List:" << endl; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - - - for (List::iterator i = l.begin(); i != l.end(); ++i) { - if ((*i) == 4) { - l.erase(i); - break; - } - } - - cout << "Removed 4 (by iterator)...\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - - /*l.remove(1); - - cout << "Removed 1 (head) (by value)...\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - */ - - for (List::iterator i = l.begin(); i != l.end(); ++i) { - if ((*i) == 2) { - l.erase(i); - break; - } - } - - cout << "Removed 2 (head) (by iterator)...\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - - /*l.remove(5); - - cout << "Removed 5 (by value)...\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - - l.remove(8); - - cout << "Removed 8 (tail) (by value)...\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - */ - for (List::iterator i = l.begin(); i != l.end(); ++i) { - if ((*i) == 7) { - l.erase(i); - break; - } - } - - cout << "Removed 7 (tail) (by iterator)...\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - - List r; - r.push_back(new List::Node(9)); - r.erase(r.begin()); - cout << "Should not see ANY numbers:\n"; - for (List::iterator i = r.begin(); i != r.end(); ++i) { - cout << *i << endl; - } - - cout << "\n\nTesting appending to an empty list:\n"; - l.clear(); - - List l2; - l2.push_back(new List::Node(1)); - l2.push_back(new List::Node(2)); - l2.push_back(new List::Node(3)); - l2.push_back(new List::Node(4)); - - cout << "l1:\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - cout << "l2:\n"; - for (List::iterator i = l2.begin(); i != l2.end(); ++i) { - cout << *i << endl; - } - - l.append(l2); - cout << "l1.append(l2):\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - cout << "\n\nAppending non-empty lists:\n"; - l2.push_back(new List::Node(5)); - l2.push_back(new List::Node(6)); - l2.push_back(new List::Node(7)); - l2.push_back(new List::Node(8)); - - cout << "l1:\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - cout << "l2:\n"; - for (List::iterator i = l2.begin(); i != l2.end(); ++i) { - cout << *i << endl; - } - - l.append(l2); - cout << "l1.append(l2):\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - - cout << "\n\nAppending an empty list:\n"; - - cout << "l1:\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - cout << "l2:\n"; - for (List::iterator i = l2.begin(); i != l2.end(); ++i) { - cout << *i << endl; - } - - l.append(l2); - cout << "l1.append(l2):\n"; - for (List::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - return 0; -} diff --git a/tests/midi_ringbuffer_test.cpp b/tests/midi_ringbuffer_test.cpp deleted file mode 100644 index 1e55caf..0000000 --- a/tests/midi_ringbuffer_test.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "raul/TimeStamp.hpp" -#include "raul/EventRingBuffer.hpp" -#include -#include -#include -#include "raul/midi_names.h" -#include -using namespace std; -using namespace Raul; - -void -read_write_test(EventRingBuffer& rb, unsigned offset) -{ - TimeStamp t(TimeUnit(TimeUnit::FRAMES, 48000), 0, 0); - size_t size; - unsigned char buf[5]; - - snprintf((char*)buf, 5, "%d", offset); - size = strlen((char*)buf); - -#ifndef NDEBUG - size_t written = rb.write(t, size, buf); -#endif - assert(written == size); - - for (size_t i=0; i < 4; ++i) - buf[i] = 0; - - rb.read(&t, &size, buf); - - cout << "t=" << t << ", s=" << size << ", b='" << buf << "'" << endl; - -} - - -int -main() -{ - EventRingBuffer rb(32); - - for (size_t i=0; i < 9999; ++i) - read_write_test(rb, i); - - return 0; -} - diff --git a/tests/path_test.cpp b/tests/path_test.cpp deleted file mode 100644 index 20d6705..0000000 --- a/tests/path_test.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include "raul/Path.hpp" - -using namespace std; -using namespace Raul; - -int -main() -{ - list names; - names.push_back("foo+1bar(baz)"); - names.push_back("ThisCRAR"); - names.push_back("NAME"); - names.push_back("thing with a bunch of spaces"); - names.push_back("thing-with-a-bunch-of-dashes"); - names.push_back("CamelCaseABC"); - names.push_back("Signal Level [dB]"); - names.push_back("Gain dB"); - names.push_back("Dry/Wet Balance"); - names.push_back("Phaser1 - Similar to CSound's phaser1 by Sean Costello"); - - cerr << "Nameification:" << endl; - for (list::iterator i = names.begin(); i != names.end(); ++i) - cerr << *i << " -> " << Path::nameify(*i) << endl; - - cerr << endl; - cerr << Path("/foo/bar") << " parent = " << Path("/foo/bar").parent() << endl; - cerr << Path("/foo") << " parent = " << Path("/foo").parent() << endl; - cerr << Path("/") << " parent = " << Path("/").parent() << endl; - - cerr << "1's are good..." << endl << endl; - - cerr << (Path("/").is_parent_of(Path("/foo"))) << endl; - cerr << (Path("/foo").is_parent_of(Path("/foo/bar"))) << endl; - cerr << !(Path("/foo").is_parent_of(Path("/foo2"))) << endl; - - cerr << endl << endl << "Descendants..." << endl; - cerr << "/ /foo " << Path::descendant_comparator("/", "/foo") << endl; - cerr << "/foo /foo/bar " << Path::descendant_comparator("/foo", "/foo/bar") << endl; - cerr << "/foo /foo " << Path::descendant_comparator("/foo", "/foo") << endl; - cerr << "/ / " << Path::descendant_comparator("/", "/") << endl; - cerr << "/baz / " << Path::descendant_comparator("/baz", "/") << endl; - - return 0; -} diff --git a/tests/quantize_test.cpp b/tests/quantize_test.cpp deleted file mode 100644 index cc10505..0000000 --- a/tests/quantize_test.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "raul/Quantizer.hpp" -#include - -using namespace std; -using namespace Raul; - - -int -main() -{ - double in = 0; - - cout << "Quantization: "; - cin >> in; - cout << endl; - - TimeStamp q(TimeUnit(TimeUnit::BEATS, 19200), in); - - while (true) { - cout << "Beats: "; - cin >> in; - - TimeStamp beats(TimeUnit(TimeUnit::BEATS, 19200), in); - - cout << "Quantized: "; - cout << Quantizer::quantize(q, beats) << endl << endl; - } - - return 0; -} - diff --git a/tests/queue_test.cpp b/tests/queue_test.cpp deleted file mode 100644 index 28d06d8..0000000 --- a/tests/queue_test.cpp +++ /dev/null @@ -1,278 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "raul/SRSWQueue.hpp" -#include "raul/SRMWQueue.hpp" -#include "raul/Thread.hpp" -#include "raul/AtomicInt.hpp" - -using namespace std; -using namespace Raul; - -static const unsigned NUM_DATA = 10; -static const unsigned QUEUE_SIZE = 1024*1024; -static const unsigned NUM_WRITERS = 2; -static const unsigned PUSHES_PER_ITERATION = 2; - -// Data to read/write using actions pumped through the queue -struct Record { - Record() : read_count(0), write_count(0) {} - - AtomicInt read_count; - AtomicInt write_count; -}; - -Record data[NUM_DATA]; - - -// Actions pumped through the queue to manipulate data -struct WriteAction { - WriteAction(unsigned idx) - : index(idx)/*, has_read(false)*/ {} - - inline void read() const { - //cout << "READ " << index << "\r\n"; - //assert(!has_read); - ++(data[index].read_count); - //has_read = true; - }; - - unsigned index; - //bool has_read; -}; - - -// The victim -SRMWQueue queue(QUEUE_SIZE); - - -class WriteThread : public Thread { -protected: - void _run() { - - cout << "Writer starting.\r\n"; - - // Wait for everything to get ready - sleep(2); - - while (true) { - for (unsigned j=0; j < PUSHES_PER_ITERATION; ++j) { - unsigned i = rand() % NUM_DATA; - if (queue.push(WriteAction(i))) { - ++(data[i].write_count); - //cout << "WRITE " << i << "\r\n"; - } else { - cerr << "FAILED WRITE\r\n"; - } - } - - // FIXME: remove! - //if (rand() % 20) - // usleep(1); - - // This thread will never cancel without this here since - // all the stuff about is cancellation point free - // (good! RT safe) - pthread_testcancel(); - } - - cout << "Writer exiting." << endl; - } -}; - - -// Returns 0 if all read count/write count pairs are equal, -// otherwise how far off total count was -unsigned -data_is_sane() -{ - unsigned ret = 0; - for (unsigned i=0; i < NUM_DATA; ++i) { - unsigned diff = abs(data[i].read_count.get() - data[i].write_count.get()); - ret += diff; - } - - return ret; -} - - -void -dump_data() -{ - for (unsigned i=0; i < NUM_DATA; ++i) { - cout << i << ":\t" << data[i].read_count.get() - << "\t : \t" << data[i].write_count.get(); - if (data[i].read_count.get() == data[i].write_count.get()) - cout << "\t OK" << endl; - else - cout << "\t FAIL" << endl; - } -} - - - -int main() -{ - unsigned long total_processed = 0; - - cout << "Testing size" << endl; - for (unsigned i=0; i < queue.capacity(); ++i) { - queue.push(i); - if (i == queue.capacity()-1) { - if (!queue.full()) { - cerr << "ERROR: Should be full at " << i - << " (size " << queue.capacity() << ")" << endl; - return -1; - } - } else { - if (queue.full()) { - cerr << "ERROR: Prematurely full at " << i - << " (size " << queue.capacity() << ")" << endl; - return -1; - } - } - } - - for (unsigned i=0; i < queue.capacity(); ++i) - queue.pop(); - - if (!queue.empty()) { - cerr << "ERROR: Should be empty" << endl; - return -1; - } - - cout << "Testing concurrent reading/writing" << endl; - vector writers(NUM_WRITERS, new WriteThread()); - - struct termios orig_term; - struct termios raw_term; - - cfmakeraw(&raw_term); - if (tcgetattr(0, &orig_term) != 0) return 1; //save terminal settings - if (tcsetattr(0, TCSANOW, &raw_term) != 0) return 1; //set to raw - fcntl(0, F_SETFL, O_NONBLOCK); //set to nonblocking IO on stdin - - - for (unsigned i=0; i < NUM_WRITERS; ++i) { - writers[i]->set_name(string("Writer ") + (char)('0' + i)); - writers[i]->start(); - } - - // Read - while (getchar() == -1) { - unsigned count = 0; - while (count < queue.capacity() && !queue.empty()) { - WriteAction action = queue.front(); - queue.pop(); - action.read(); - ++count; - ++total_processed; - } - - /*if (count > 0) - cout << "Processed " << count << " requests\t\t" - << "(total " << total_processed << ")\r\n";*/ - - //if (total_processed > 0 && total_processed % 128l == 0) - // cout << "Total processed: " << total_processed << "\r\n"; - } - - if (tcsetattr(0, TCSANOW, &orig_term) != 0) return 1; //restore - - cout << "Finishing." << endl; - - // Stop the writers - for (unsigned i=0; i < NUM_WRITERS; ++i) - writers[i]->stop(); - - cout << "\n\n****************** DONE *********************\n\n"; - - unsigned leftovers = 0; - - // Drain anything left in the queue - while (!queue.empty()) { - WriteAction action = queue.front(); - queue.pop(); - action.read(); - leftovers++; - ++total_processed; - } - - if (leftovers > 0) - cout << "Processed " << leftovers << " leftovers." << endl; - - - cout << "\n\n*********************************************\n\n"; - - cout << "Total processed: " << total_processed << endl; - if (total_processed > INT_MAX) - cout << "(Counter had to wrap)" << endl; - else - cout << "(Counter did NOT have to wrap)" << endl; - - - unsigned diff = data_is_sane(); - - if (diff == 0) { - cout << "PASS" << endl; - } else { - cout << "FAILED BY " << diff << endl; - // dump_data(); - } - - dump_data(); - - return 0; -} - - -#if 0 -int main() -{ - //SRSWQueue q(10); - SRMWQueue q(10); - - cout << "New queue. Should be empty: " << q.empty() << endl; - cout << "Capacity: " << q.capacity() << endl; - //cout << "Fill: " << q.fill() << endl; - - for (uint i=0; i < 5; ++i) { - q.push(i); - assert(!q.full()); - q.pop(); - } - cout << "Pushed and popped 5 elements. Queue should be empty: " << q.empty() << endl; - //cout << "Fill: " << q.fill() << endl; - - for (uint i=10; i < 20; ++i) { - assert(q.push(i)); - } - cout << "Pushed 10 elements. Queue should be full: " << q.full() << endl; - //cout << "Fill: " << q.fill() << endl; - - cout << "The digits 10->19 should print: " << endl; - while (!q.empty()) { - int foo = q.front(); - q.pop(); - cout << "Popped: " << foo << endl; - } - cout << "Queue should be empty: " << q.empty() << endl; - //cout << "Fill: " << q.fill() << endl; - - cout << "Attempting to add eleven elements to queue of size 10. Only first 10 should succeed:" << endl; - for (uint i=20; i <= 39; ++i) { - cout << i; - //cout << " - Fill: " << q.fill(); - cout << " - full: " << q.full(); - cout << ", succeeded: " << q.push(i) << endl; - } - - return 0; -} -#endif - diff --git a/tests/ringbuffer_test.cpp b/tests/ringbuffer_test.cpp deleted file mode 100644 index 87b81c6..0000000 --- a/tests/ringbuffer_test.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include "raul/RingBuffer.hpp" - -using namespace std; -using namespace Raul; - -void -print_buf(size_t size, char* buf) -{ - cout << "{ "; - for (size_t i=0; i < size; ++i) { - cout << buf[i]; - if (i < size-1) - cout << ", "; - } - - cout << " }" << endl; -} - - -int -main() -{ - RingBuffer rb(5); - - char ev[] = { 'a', 'b', 'c' }; - - rb.write(3, ev); - - char buf[3]; - rb.read(3, buf); - print_buf(3, buf); - - char ev2[] = { 'd', 'e', 'f' }; - rb.write(3, ev2); - - - size_t read = rb.read(3, buf); - if (read < 3) - rb.read(3 - read, buf + read); - - print_buf(3, buf); - - return 0; -} - diff --git a/tests/smf_test.cpp b/tests/smf_test.cpp deleted file mode 100644 index 40465ed..0000000 --- a/tests/smf_test.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include -#include "raul/SMFReader.hpp" -#include "raul/SMFWriter.hpp" - -using namespace std; -using namespace Raul; - - -int -main(int argc, char** argv) -{ - const char* filename = NULL; - - if (argc < 2) { - filename = "./test.mid"; - SMFWriter writer(TimeUnit(TimeUnit::BEATS, 19200)); - writer.start(string(filename), TimeStamp(writer.unit(), 0, 0)); - writer.finish(); - cout << "Wrote " << filename << " with PPQN = " << writer.unit().ppt() << endl; - - } else { - filename = argv[1]; - } - - - SMFReader reader; - bool opened = reader.open(filename); - - if (!opened) { - cerr << "Unable to open SMF file " << filename << endl; - return -1; - } - - cout << "Opened SMF file " << filename << endl; - - cout << "Type: " << reader.type() << endl; - cout << "Num tracks: " << reader.num_tracks() << endl; - cout << "PPQN: " << reader.ppqn() << endl; - - for (unsigned t=1; t <= reader.num_tracks(); ++t) { - cout << "******** Track " << t << " ********" << endl; - reader.seek_to_track(t); - - unsigned char buf[4]; - uint32_t ev_size; - uint32_t ev_delta_time; - while (reader.read_event(4, buf, &ev_size, &ev_delta_time) >= 0) { - - cout << "Event, size = " << ev_size << ", time = " << ev_delta_time; - cout << ":\t"; - cout.flags(ios::hex); - for (uint32_t i=0; i < ev_size; ++i) { - cout << "0x" << (int)buf[i] << " "; - } - cout.flags(ios::dec); - cout << endl; - } - } - - return 0; -} diff --git a/tests/table_test.cpp b/tests/table_test.cpp deleted file mode 100644 index 5e83479..0000000 --- a/tests/table_test.cpp +++ /dev/null @@ -1,384 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "raul/PathTable.hpp" -#include "raul/Table.hpp" -#include "raul/TableImpl.hpp" - -//#define WITH_TR1 1 - -#ifdef WITH_TR1 - #define BOOST_MULTI_INDEX_DISABLE_SERIALIZATION 1 - #include - #include -#endif - -using namespace Raul; -using namespace std; - -int range_end_val; - -bool range_comparator(const int& a, const int& b) -{ - bool ret = (b >= a && b <= range_end_val); - //cout << "COMP: " << a << " . " << b << " = " << ret << endl; - return ret; -} - -void benchmark(size_t n); - -int -main(int argc, char** argv) -{ - if (argc == 3 && !strcmp(argv[1], "-b")) { - benchmark(atoi(argv[2])); - return 0; - } - - cout << "run with -b num_elems to benchmark" << endl; - srand(time(NULL)); - - range_end_val = rand()%10; - - Table t; - for (size_t i=0; i < 20; ++i) { - int val = rand()%10; - t.insert(make_pair(val, val)); - } - - t[20] = 20; - t[21] = 21; - - cout << "Contents:" << endl; - for (Table::const_iterator i = t.begin(); i != t.end(); ++i) - cout << i->first << " "; - cout << endl; - - std::cout << "Range " << t.begin()->first << " .. " << range_end_val << std::endl; - - Table::const_iterator range_begin = t.begin(); - ++range_begin; ++range_begin; - - Table::iterator range_end = t.find_range_end(t.begin(), range_comparator); - - for (Table::const_iterator i = t.begin(); i != range_end; ++i) - cout << i->first << " "; - cout << endl; - - Table::iterator first = t.begin(); - ++first; - Table::iterator last = first; - ++last; ++last; ++last; - - cout << "Erasing elements 1..3:" << endl; - t.erase(first, last); - - for (Table::const_iterator i = t.begin(); i != t.end(); ++i) - cout << i->first << " "; - cout << endl; - - cout << "Erasing elements 0..3" << endl; - first = t.begin(); - last = first; - ++last; ++last; ++last; - t.erase(first, last); - - for (Table::const_iterator i = t.begin(); i != t.end(); ++i) - cout << i->first << " "; - cout << endl; - - cout << "Erasing elements end()-2..end()" << endl; - last = t.end(); - first = last; - --first; --first; - t.erase(first, last); - - for (Table::const_iterator i = t.begin(); i != t.end(); ++i) - cout << i->first << " "; - cout << endl; - - cout << "Erasing everything" << endl; - first = t.begin(); - last = t.end(); - t.erase(first, last); - - for (Table::const_iterator i = t.begin(); i != t.end(); ++i) - cout << i->first << " "; - cout << endl; - - /* **** */ - - PathTable pt; - pt.insert(make_pair("/foo", 'a')); - pt.insert(make_pair("/bar", 'a')); - pt.insert(make_pair("/bar/baz", 'b')); - pt.insert(make_pair("/bar/bazz/NO", 'c')); - pt.insert(make_pair("/bar/baz/YEEEAH", 'c')); - pt.insert(make_pair("/bar/baz/YEEEAH/BOOOEEEEE", 'c')); - pt.insert(make_pair("/bar/buzz", 'b')); - pt.insert(make_pair("/bar/buzz/WHAT", 'c')); - pt.insert(make_pair("/bar/buzz/WHHHhhhhhAT", 'c')); - pt.insert(make_pair("/quux", 'a')); - - cout << "Paths: " << endl; - for (PathTable::const_iterator i = pt.begin(); i != pt.end(); ++i) - cout << i->first << " "; - cout << endl; - - PathTable::const_iterator descendants_begin = pt.begin(); - size_t begin_index = rand() % pt.size(); - for (size_t i=0; i < begin_index; ++i) - ++descendants_begin; - - cout << "\nDescendants of " << descendants_begin->first << endl; - PathTable::const_iterator descendants_end = pt.find_descendants_end(descendants_begin); - - for (PathTable::const_iterator i = pt.begin(); i != descendants_end; ++i) - cout << i->first << " "; - cout << endl; - - const Path yank_path("/bar"); - PathTable::iterator quux = pt.find(yank_path); - assert(quux != pt.end()); - PathTable::iterator quux_end = pt.find_descendants_end(quux ); - assert(quux_end != quux); - - SharedPtr< Table > yanked = pt.yank(quux, quux_end); - - cout << "Yanked " << yank_path << endl; - for (PathTable::const_iterator i = pt.begin(); i != pt.end(); ++i) - cout << i->first << " "; - cout << endl; - - pt.cram(*yanked.get()); - - cout << "Crammed " << yank_path << endl; - for (PathTable::const_iterator i = pt.begin(); i != pt.end(); ++i) - cout << i->first << " "; - cout << endl; - - /* **** */ - - cout << "\nAssuming you built with debugging, if this continues to run " - << "and chews your CPU without dying, everything's good." << endl; - - - Table st; - - st.insert(make_pair("apple", "core")); - st.insert(make_pair("candy", "cane")); - st.insert(make_pair("banana", "peel")); - //st["alpha"] = "zero"; - //st["zeta"] = "one"; - - st.erase("banana"); - - for (Table::const_iterator i = t.begin(); i != t.end(); ++i) - cout << i->first << " "; - cout << endl; - - while (true) { - Table t; - - size_t table_size = (rand() % 1000) + 1; - - for (size_t i=0; i < table_size; ++i) { - int val = rand()%100; - t.insert(make_pair(val, ((val + 3) * 17))); - } - - for (int i=0; i < (int)table_size; ++i) { - int val = rand()%100; - Table::iterator iter = t.find(val); - assert(iter == t.end() || iter->second == (val + 3) * 17); - } - - /*cout << "CONTENTS:" << endl; - - for (Table::const_iterator i = t.begin(); i != t.end(); ++i) { - cout << i->first << ": " << i->second << endl; - } - - Table::iterator i = t.find(7); - if (i != t.end()) - cout << "Find: 7: " << i->second << endl; - */ - } - - return 0; -} - -string -random_string() -{ - string ret(60, 'A' + (rand() % 26)); - return ret; -} - - -void -benchmark(size_t n) -{ - cout << "Benchmarking with n = " << n << endl; - - int useless_accumulator = 0; - - srand(time(NULL)); - - vector values(n); - for (size_t i=0; i < n; ++i) - values.push_back(random_string()); - - timeval t1; - t1.tv_sec=0; - t1.tv_usec=0; - - timeval t2; - t2.tv_sec=0; - t2.tv_usec=0; - - - /** std::map **/ - - std::map m; - - gettimeofday(&t1, NULL); - - for (size_t i=0; i < n; ++i) - m.insert(make_pair(values[i], i)); - - gettimeofday(&t2, NULL); - - float delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; - - cout << "std::map time to insert " << n << " values: \t" << delta_t << endl; - - gettimeofday(&t1, NULL); - - for (size_t i=0; i < n; ++i) - useless_accumulator += m.find(values[i])->second; - - gettimeofday(&t2, NULL); - - delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; - - cout << "std::map time to lookup " << n << " values: \t" << delta_t << endl; - - - /** std::set **/ - - std::set s; - - gettimeofday(&t1, NULL); - - for (size_t i=0; i < n; ++i) - s.insert(values[i]); - - gettimeofday(&t2, NULL); - - delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; - - cout << "std::set time to insert " << n << " values: \t" << delta_t << endl; - - gettimeofday(&t1, NULL); - - for (size_t i=0; i < n; ++i) - useless_accumulator += (int)(*s.find(values[i]))[0]; - - gettimeofday(&t2, NULL); - - delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; - - cout << "std::set time to lookup " << n << " values: \t" << delta_t << endl; - - - /** sorted std::vector **/ - - /*std::vector v; - - gettimeofday(&t1, NULL); - - for (size_t i=0; i < n; ++i) - v.push_back(values[i]); - - sort(v.begin(), v.end()); - - gettimeofday(&t2, NULL); - - delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; - - cout << "std::vector (sorted) time to insert " << n << " values: \t" << delta_t << endl; - - gettimeofday(&t1, NULL); - - for (size_t i=0; i < n; ++i) - useless_accumulator += *lower_bound(v.begin(), v.end(), values[i]); - - gettimeofday(&t2, NULL); - - delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; - - cout << "std::vector (sorted) time to lookup " << n << " values: \t" << delta_t << endl;*/ - - - /** Raul::Table **/ - - Raul::Table t(n); - - gettimeofday(&t1, NULL); - - for (size_t i=0; i < n; ++i) - t.insert(make_pair(values[i], i)); - - gettimeofday(&t2, NULL); - - delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; - - cout << "Raul::Table time to insert " << n << " values: " << delta_t << endl; - - gettimeofday(&t1, NULL); - - for (size_t i=0; i < n; ++i) - useless_accumulator += t.find(values[i])->second; - - gettimeofday(&t2, NULL); - - delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; - - cout << "Raul::Table time to lookup " << n << " values: \t" << delta_t << endl; - - -#ifdef WITH_TR1 - /** boost::hash && std::unordered_map **/ - - tr1::unordered_map > um; - - gettimeofday(&t1, NULL); - - um.rehash(n); - - for (size_t i=0; i < n; ++i) - um.insert(make_pair(values[i], i)); - - gettimeofday(&t2, NULL); - - delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; - - cout << "tr1::unordered_map + boost::hash time to insert " << n << " values: \t" << delta_t << endl; - - gettimeofday(&t1, NULL); - - for (size_t i=0; i < n; ++i) - useless_accumulator += um.find(values[i])->second; - - gettimeofday(&t2, NULL); - - delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; - - cout << "tr1::unordered_map + boost::hash time to lookup " << n << " values: \t" << delta_t << endl; -#endif -} - diff --git a/tests/thread_test.cpp b/tests/thread_test.cpp deleted file mode 100644 index fd7a411..0000000 --- a/tests/thread_test.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include "raul/Thread.hpp" - -using namespace std; -using namespace Raul; - -int -main() -{ - Thread& this_thread = Thread::get(); - this_thread.set_name("Main"); - - cout << "Thread name should be Main" << endl; - - cout << "Thread name: " << Thread::get().name() << endl; - - return 0; -} - diff --git a/tests/time_test.cpp b/tests/time_test.cpp deleted file mode 100644 index 2b53207..0000000 --- a/tests/time_test.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "raul/TimeStamp.hpp" -#include "raul/TimeSlice.hpp" -#include - -using namespace std; -using namespace Raul; - - -int -main() -{ - TimeUnit unit(TimeUnit::BEATS, 19200); - TimeSlice ts(48000, 19200, 120.0); - - double in_double; - cout << "Beats: "; - cin >> in_double; - - TimeStamp t(unit, (uint32_t)in_double, - (uint32_t)((in_double - (uint32_t)in_double) * unit.ppt())); - - cout << "\tSeconds: "; - cout << ts.beats_to_seconds(t); - cout << endl; - - cout << "\tTicks: "; - cout << ts.beats_to_ticks(t); - cout << endl; - - return 0; -} - diff --git a/tests/wscript b/tests/wscript deleted file mode 100644 index 1997c1a..0000000 --- a/tests/wscript +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -def build(bld): - tests = ''' - path_test - thread_test - queue_test - ringbuffer_test - midi_ringbuffer_test - atomic_test - list_test - time_test - quantize_test - smf_test - table_test - ''' - if bld.env['BUILD_TESTS']: - for i in tests.split(): - obj = bld.new_task_gen('cxx', 'program') - obj.source = i + '.cpp' - obj.includes = '..' - obj.uselib_local = 'libraul' - obj.target = i - obj.install_path = '' - -- cgit v1.2.1