Permalink
Browse files

Import new stream structure from streaming branch.

The matrix app works, but rtree and bkdtree don't and have been commented out.
The test_ami_btree and test_correctness tests don't work and have been commented out.
The test_bte unit test has been commented out.
  • Loading branch information...
Mortal committed Sep 5, 2011
1 parent 80bcc1c commit d01883b1a614e9e209b095ccd7099f967211f2e8
View
@@ -1,4 +1,4 @@
add_subdirectory(matrix)
add_subdirectory(rtree)
add_subdirectory(bkdtree)
#add_subdirectory(rtree)
#add_subdirectory(bkdtree)
@@ -31,6 +31,7 @@
// The new getopts() argument-parsing function.
#include "getopts.h"
#include <tpie/memory.h>
#include <tpie/stream.h>
using namespace tpie;
View
@@ -40,11 +40,11 @@ add_tpie_test(test_sort)
add_tpie_test(test_ami_pmerge)
add_tpie_test(test_ami_sort24)
add_tpie_test(test_big_scan)
add_tpie_test(test_ami_btree)
#add_tpie_test(test_ami_btree)
#add_tpie_test(test_ami_matrix_pad)
add_tpie_test(test_ami_queue)
add_tpie_test(test_ami_sort)
add_tpie_test(test_correctness)
#add_tpie_test(test_correctness)
if(NOT WIN32)
add_subdirectory(speed_regression)
View
@@ -28,6 +28,8 @@
#include "getopts.h"
#include <tpie/stream.h>
#include <tpie/memory.h>
using namespace tpie;
void parse_args(int argc, char **argv, struct options *application_opts,
View
@@ -35,6 +35,9 @@
// Get stream arithmetic.
#include <tpie/stream_arith.h>
// Get some memory.
#include <tpie/memory.h>
using namespace tpie;
static char def_crf[] = "osc.txt";
View
@@ -22,6 +22,9 @@
#include <tpie/stream.h>
#include "getopts.h"
#include <cstring>
#include <tpie/memory.h>
using namespace tpie;
//snprintf is different on WIN/Unix platforms
View
@@ -44,18 +44,18 @@ add_fulltest(external_sort large)
add_unittest(external_stack small named)
add_executable(test_bte test_bte.cpp)
set_target_properties(test_bte PROPERTIES FOLDER tpie/unittest)
target_link_libraries(test_bte tpie)
if(NOT WIN32)
set(BTES ${BTES} ufs mmap)
endif(NOT WIN32)
set(BTES ${BTES} ami_stream cache stdio)
foreach(bte ${BTES})
foreach(test basic randomread array)
add_test(bte_${bte}_${test} test_bte ${bte} ${test})
endforeach(test)
endforeach(bte)
#add_executable(test_bte test_bte.cpp)
#set_target_properties(test_bte PROPERTIES FOLDER tpie/unittest)
#target_link_libraries(test_bte tpie)
#if(NOT WIN32)
#set(BTES ${BTES} ufs mmap)
#endif(NOT WIN32)
#set(BTES ${BTES} ami_stream cache stdio)
#foreach(bte ${BTES})
# foreach(test basic randomread array)
# add_test(bte_${bte}_${test} test_bte ${bte} ${test})
# endforeach(test)
#endforeach(bte)
View
@@ -0,0 +1,224 @@
// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
// vi:set ts=4 sts=4 sw=4 noet :
// Copyright 2009, The TPIE development team
// This file is part of TPIE.
// TPIE is free software: you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
// TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with TPIE. If not, see <http://www.gnu.org/licenses/>
#include "../app_config.h"
#include <tpie/portability.h>
#include <cstring>
#include <tpie/file_stream.h>
#include <tpie/file.h>
#include <tpie/util.h>
#include <tpie/file_accessor/stdio.h>
#ifndef WIN32
#include <tpie/file_accessor/posix.h>
#else //WIN32
#include <tpie/file_accessor/win32.h>
#endif //WIN32
using namespace std;
using namespace tpie;
#define ERR(x) {cerr << x << endl; exit(1);}
template <typename T>
void test_file_accessor() {
try {
remove("tmp");
{
int d=42;
T x;
x.open("tmp", false, true, sizeof(int), sizeof(int));
if (x.size() != 0) ERR("New stream has wrong size");
if (x.path() != "tmp") ERR("Wrong path");
x.write(&d, 0, 1);
x.write(&d, 1, 1);
int ud=314;
x.write_user_data(&ud);
try {
x.read(&d, 0, 1);
ERR("Read should faild");
} catch(io_exception &) {
//Do nothing
}
if (x.size() != 2) ERR("Wrong size");
x.close();
}
try {
T x;
x.open("tmp", true, false, sizeof(int)+1, sizeof(int));
ERR("Opened file with wrong item size");
} catch(invalid_file_exception&) {
//Do nothing
}
try {
T x;
x.open("tmp", true, false, sizeof(int), 0);
ERR("Opened file with wrong user data size");
} catch(invalid_file_exception&) {
//Do nothing
}
{
int d;
T x;
x.open("tmp", true, true, sizeof(int), sizeof(int));
if (x.read(&d, 1, 1) != 1 || d != 42) ERR("Read failed");
d=12;
x.write(&d, 1, 1);
x.write(&d, 2, 1);
if (x.read(&d, 0, 1) != 1 || d != 42) ERR("Read failed");
if (x.read(&d, 1, 1) != 1 || d != 12) ERR("Read failed");
if (x.read(&d, 2, 1) != 1 || d != 12) ERR("Read failed");
int ud;
x.read_user_data(&ud);
if (ud != 314) ERR("Wrong user data");
if (x.size() != 3) ERR("Wrong size");
x.close();
}
{
T x;
x.open("tmp", true, false, sizeof(int), sizeof(int) );
try {
int d=44;
x.write(&d, 0, 1);
ERR("Write should faild");
} catch(io_exception &) {
//Do nothing
}
int d;
if (x.read(&d, 0, 1) != 1 || d != 42) ERR("Read failed");
if (x.read(&d, 1, 1) != 1 || d != 12) ERR("Read failed");
if (x.read(&d, 2, 1) != 1 || d != 12) ERR("Read failed");
x.close();
}
} catch(io_exception & e) {
ERR("io_exception " << e.what());
} catch(invalid_file_exception& e) {
ERR("invalid_file_exception " << e.what());
} catch(tpie::exception & e) {
ERR("Other exception " << e.what());
}
remove("tmp");
}
int main(int argc, char ** argv) {
//TODO add memory allocation tests
if (argc == 2 && !strcmp(argv[1], "file_accessor_stdio")) {
test_file_accessor<file_accessor::stdio>();
#ifndef WIN32
} else if (argc == 2 && !strcmp(argv[1], "file_accessor_posix")) {
test_file_accessor<file_accessor::posix>();
#else //WIN32
} else if (argc == 2 && !strcmp(argv[1], "file_accessor_win32")) {
test_file_accessor<file_accessor::win32>();
#endif //WIN32
} else if (argc == 2 && !strcmp(argv[1], "file_stream")) {
///First a simple test
double blockFactor=file_base::calculate_block_factor(128*sizeof(int));
remove("tmp");
int count=40*1024;
{
file_stream<int> stream(blockFactor);
stream.open("tmp", file_base::write, sizeof(int));
stream.write_user_data<int>(42);
if (stream.size() != 0) ERR("size failed(1)");
for(int i=0; i < count; ++i)
stream.write((i*8209)%8273);
if (stream.size() != (size_t)count) ERR("size failed(2)");
stream.close();
}
{
file_stream<int> stream(blockFactor);
stream.open("tmp", file_base::read, sizeof(int));
if (stream.size() != (size_t)count) ERR("size failed(3)");
for(int i=0; i< count; ++i) {
if (stream.can_read() == false) ERR("can_read failed");
if (stream.read() != (i*8209)%8273) ERR("read failed");
}
if (stream.can_read() == true) ERR("can_read failed (2)");
try {
int r =stream.read();
unused(r);
ERR("read did not fail as expected");
} catch(end_of_stream_exception &) {
//Do nothing
}
stream.seek(-1, file_base::end);
for(int i=count-1; i >= 0; --i) {
if (stream.can_read_back() == false) {
ERR("can_read_back failed");
}
if (stream.read_back() != (i*8209)%8273) ERR("read back failed");
}
if (stream.can_read_back() == true) ERR("can_read_back failed (2)");
int y;
stream.read_user_data<int>(y);
if (y != 42) ERR("read did not fail as expected");
stream.close();
}
} else if (argc == 2 && !strcmp(argv[1], "substreams")) {
double blockFactor=file_base::calculate_block_factor(128*sizeof(int));
temp_file tmp;
tpie::remove("tmp");
file<int> f(blockFactor);
f.open(tmp.path(), file_base::read_write);
tpie::seed_random(1234);
const int cnt=4;
const int size=128;
typedef file<int>::stream stream_t;
stream_t ** streams = new stream_t*[cnt];
for(int i=0; i < cnt; ++i)
streams[i] = new stream_t(f);
int content[size];
for(int i=0; i < size; ++i) {
content[i] = tpie::random();
streams[0]->write(content[i]);
}
for(int i=0; i < 20000; ++i ) {
int l=tpie::random()%size;
int s=tpie::random()%cnt;
streams[s]->seek(l);
if (tpie::random() % 2 == 0) {
if (streams[s]->read() != content[l]) ERR("read failed(2)");
} else {
content[l] = tpie::random();
streams[s]->write(content[l]);
}
}
for(int i=0; i < cnt; ++i)
delete streams[i];
delete[] streams;
} else {
return 1;
}
return 0;
}
@@ -20,6 +20,7 @@
#include <tpie/priority_queue.h>
#include <vector>
#include "priority_queue.h"
using namespace tpie;
using namespace std;
Oops, something went wrong.

0 comments on commit d01883b

Please sign in to comment.