2009-04-14 20:21:05 +00:00
|
|
|
/*--- This software is copyrighted by the Regents of the University
|
2007-10-22 20:48:12 +00:00
|
|
|
of
|
2006-10-13 04:39:03 +00:00
|
|
|
California, and other parties. The following terms apply to all files
|
|
|
|
associated with the software unless explicitly disclaimed in
|
|
|
|
individual files.
|
|
|
|
|
|
|
|
The authors hereby grant permission to use, copy, modify, distribute,
|
|
|
|
and license this software and its documentation for any purpose,
|
|
|
|
provided that existing copyright notices are retained in all copies
|
|
|
|
and that this notice is included verbatim in any distributions. No
|
|
|
|
written agreement, license, or royalty fee is required for any of the
|
|
|
|
authorized uses. Modifications to this software may be copyrighted by
|
|
|
|
their authors and need not follow the licensing terms described here,
|
|
|
|
provided that the new terms are clearly indicated on the first page of
|
|
|
|
each file where they apply.
|
|
|
|
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
|
|
|
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
|
|
|
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
|
|
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
|
|
|
|
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
|
|
|
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
|
|
|
|
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
|
|
|
U.S. government, the Government shall have only "Restricted Rights" in
|
|
|
|
the software and related documentation as defined in the Federal
|
|
|
|
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
|
|
|
|
acquiring the software on behalf of the Department of Defense, the
|
|
|
|
software shall be classified as "Commercial Computer Software" and the
|
|
|
|
Government shall have only "Restricted Rights" as defined in Clause
|
|
|
|
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
|
|
|
authors grant the U.S. Government and others acting in its behalf
|
|
|
|
permission to use and distribute the software in accordance with the
|
|
|
|
terms specified in this license.
|
|
|
|
---*/
|
2009-04-14 20:21:05 +00:00
|
|
|
#include "../check_includes.h"
|
|
|
|
|
2007-06-11 21:36:57 +00:00
|
|
|
#include <stasis/io/handle.h>
|
2009-05-08 04:56:34 +00:00
|
|
|
#include <stasis/constants.h>
|
|
|
|
#include <stasis/flags.h>
|
2006-10-13 04:39:03 +00:00
|
|
|
#include <assert.h>
|
2006-10-18 00:57:36 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
#define LOG_NAME "check_io.log"
|
|
|
|
|
2007-10-23 23:26:33 +00:00
|
|
|
int handle_truncate_is_supported = 1;
|
2006-10-13 04:39:03 +00:00
|
|
|
|
2007-10-23 23:26:33 +00:00
|
|
|
void handle_smoketest(stasis_handle_t * h) {
|
2006-10-13 04:39:03 +00:00
|
|
|
|
|
|
|
const int one = 0x11111111;
|
|
|
|
const int two = 0x22222222;
|
|
|
|
const int three = 0x33333333;
|
|
|
|
const int four = 0x44444444;
|
|
|
|
|
2006-10-26 05:48:30 +00:00
|
|
|
lsn_t off;
|
|
|
|
h->append(h, &off, 0, 0);
|
|
|
|
assert(off == 0);
|
|
|
|
|
2006-10-17 03:28:24 +00:00
|
|
|
assert((!h->num_copies(h)) || (!h->num_copies_buffer(h)));
|
2006-10-13 04:39:03 +00:00
|
|
|
|
|
|
|
assert(0 == h->start_position(h) ||
|
|
|
|
0 == h->end_position(h));
|
|
|
|
|
|
|
|
assert(! h->write(h, 0, (byte*)&one, sizeof(int)));
|
|
|
|
|
|
|
|
int one_read = 0;
|
2006-10-18 00:57:36 +00:00
|
|
|
int ret = h->read(h, 0, (byte*)&one_read, sizeof(int));
|
|
|
|
assert(!ret);
|
2006-10-13 04:39:03 +00:00
|
|
|
assert(one_read == one);
|
|
|
|
stasis_write_buffer_t * w = h->write_buffer(h, sizeof(int), sizeof(int));
|
|
|
|
*((int*)(w->buf)) = two;
|
|
|
|
w->h->release_write_buffer(w);
|
2009-04-14 20:21:05 +00:00
|
|
|
one_read = 0;
|
2006-10-13 04:39:03 +00:00
|
|
|
stasis_read_buffer_t * r = h->read_buffer(h, 0, sizeof(int));
|
|
|
|
one_read = *((int*)(r->buf));
|
|
|
|
r->h->release_read_buffer(r);
|
|
|
|
assert(one == one_read);
|
|
|
|
|
|
|
|
int two_read = 0;
|
|
|
|
assert(! h->read(h, sizeof(int), (byte*)&two_read, sizeof(int)));
|
|
|
|
assert(two == two_read);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
assert(! h->append(h, &off, (byte*)&three, sizeof(int)));
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
w = h->append_buffer(h, sizeof(int));
|
|
|
|
memcpy(w->buf, &four, sizeof(int));
|
|
|
|
w->h->release_write_buffer(w);
|
2007-10-23 23:26:33 +00:00
|
|
|
if(handle_truncate_is_supported) {
|
|
|
|
h->truncate_start(h, 2 * sizeof(int));
|
|
|
|
}
|
2006-10-13 04:39:03 +00:00
|
|
|
int three_read = 0;
|
|
|
|
int four_read = 0;
|
2009-04-14 20:21:05 +00:00
|
|
|
ret = h->read(h, 2*sizeof(int), (byte*)&three_read, sizeof(int));
|
2006-11-21 06:49:16 +00:00
|
|
|
assert(!ret);
|
2006-10-13 04:39:03 +00:00
|
|
|
|
|
|
|
r = h->read_buffer(h, 3*sizeof(int), sizeof(int));
|
|
|
|
memcpy(&four_read, r->buf, sizeof(int));
|
|
|
|
r->h->release_read_buffer(r);
|
|
|
|
|
|
|
|
assert(three == three_read);
|
|
|
|
assert(four == four_read);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
typedef struct {
|
2006-10-13 04:39:03 +00:00
|
|
|
int * values;
|
|
|
|
int count;
|
|
|
|
stasis_handle_t * h;
|
|
|
|
} thread_arg;
|
|
|
|
|
|
|
|
#define VALUE_COUNT 100000
|
|
|
|
#define THREAD_COUNT 100
|
|
|
|
#define OPS_PER_THREAD 500000
|
|
|
|
|
|
|
|
lsn_t trunc_val;
|
|
|
|
pthread_mutex_t trunc_mut = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
void load_handle(thread_arg* t) {
|
|
|
|
lsn_t * offsets = malloc(t->count * sizeof(lsn_t));
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
stasis_handle_t * h = t->h;
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = 0; i < t->count; i++) {
|
2006-10-13 04:39:03 +00:00
|
|
|
offsets[i] = -1;
|
|
|
|
}
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = 0; i < OPS_PER_THREAD; i++) {
|
2006-10-13 04:39:03 +00:00
|
|
|
int val = myrandom(t->count);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
|
|
|
if(offsets[val] == -1) {
|
2006-10-13 04:39:03 +00:00
|
|
|
// Need to write it somewhere.
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
long choice = myrandom(4);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
|
|
|
switch(choice) {
|
2006-10-13 04:39:03 +00:00
|
|
|
case 0: { // overwrite old entry with write()
|
|
|
|
long val2 = myrandom(t->count);
|
|
|
|
offsets[val] = offsets[val2];
|
|
|
|
offsets[val2] = -1;
|
2009-04-14 20:21:05 +00:00
|
|
|
if(offsets[val] != -1) {
|
2006-10-13 04:39:03 +00:00
|
|
|
int ret = h->write(h, offsets[val], (const byte*)&(t->values[val]), sizeof(int));
|
|
|
|
if(ret) {
|
|
|
|
assert(ret == EDOM);
|
|
|
|
offsets[val] = -1;
|
|
|
|
i--;
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
} else {
|
2006-10-13 04:39:03 +00:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 1: { // overwrite old entry with write_buffer()
|
|
|
|
long val2 = myrandom(t->count);
|
|
|
|
offsets[val] = offsets[val2];
|
|
|
|
offsets[val2] = -1;
|
2009-04-14 20:21:05 +00:00
|
|
|
if(offsets[val] != -1) {
|
2006-10-13 04:39:03 +00:00
|
|
|
stasis_write_buffer_t * w = h->write_buffer(h, offsets[val], sizeof(int));
|
2009-04-14 20:21:05 +00:00
|
|
|
if(!w->error) {
|
2006-10-13 04:39:03 +00:00
|
|
|
*((int*)w->buf) = t->values[val];
|
|
|
|
assert(w->len == sizeof(int));
|
|
|
|
assert(w->off == offsets[val]);
|
2009-04-14 20:21:05 +00:00
|
|
|
} else {
|
2006-10-13 04:39:03 +00:00
|
|
|
assert(w->error == EDOM);
|
2009-04-14 20:21:05 +00:00
|
|
|
offsets[val] = -1;
|
2006-10-13 04:39:03 +00:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
w->h->release_write_buffer(w);
|
|
|
|
} else {
|
2009-04-14 20:21:05 +00:00
|
|
|
i--;
|
2006-10-13 04:39:03 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 2: { // append
|
2006-11-21 06:49:16 +00:00
|
|
|
lsn_t oldend = h->end_position(h);
|
2006-10-13 04:39:03 +00:00
|
|
|
int ret = h->append(h, &(offsets[val]), (const byte*)&(t->values[val]), sizeof(int));
|
2006-11-21 06:49:16 +00:00
|
|
|
assert(!ret || oldend < h->start_position(h));
|
2006-10-13 04:39:03 +00:00
|
|
|
} break;
|
|
|
|
case 3: { // append_buffer
|
2006-11-21 06:49:16 +00:00
|
|
|
lsn_t oldend = h->end_position(h);
|
2006-10-13 04:39:03 +00:00
|
|
|
stasis_write_buffer_t * w = h->append_buffer(h, sizeof(int));
|
|
|
|
if(!w->error) {
|
|
|
|
*((int*)w->buf) = t->values[val];
|
|
|
|
assert(w->len == sizeof(int));
|
|
|
|
offsets[val] = w->off;
|
|
|
|
} else {
|
2006-11-21 06:49:16 +00:00
|
|
|
assert(oldend < h->start_position(h));
|
2006-10-13 04:39:03 +00:00
|
|
|
}
|
|
|
|
w->h->release_write_buffer(w);
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
int check;
|
|
|
|
int ret = h->read(h, offsets[val], (byte*)&check, sizeof(int));
|
2009-04-14 20:21:05 +00:00
|
|
|
if(!ret) {
|
2006-10-13 04:39:03 +00:00
|
|
|
assert(check == t->values[val]);
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// Read the value.
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
long choice = myrandom(2);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
|
|
|
switch(choice) {
|
2006-10-13 04:39:03 +00:00
|
|
|
case 0: { // read
|
2006-10-18 00:57:36 +00:00
|
|
|
int j = -1;
|
2006-10-13 04:39:03 +00:00
|
|
|
int ret = h->read(h, offsets[val], (byte*)&j, sizeof(int));
|
2009-04-14 20:21:05 +00:00
|
|
|
if(!ret) {
|
2006-10-13 04:39:03 +00:00
|
|
|
assert(j == t->values[val]);
|
|
|
|
} else {
|
|
|
|
assert(ret == EDOM);
|
|
|
|
assert(h->start_position(h) > offsets[val]);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 1: { // read_buffer
|
|
|
|
stasis_read_buffer_t * r = h->read_buffer(h, offsets[val], sizeof(int));
|
2009-04-14 20:21:05 +00:00
|
|
|
if(!r->error) {
|
2006-10-13 04:39:03 +00:00
|
|
|
assert(*(int*)(r->buf) == t->values[val]);
|
|
|
|
assert(r->len == sizeof(int));
|
2006-10-17 03:28:24 +00:00
|
|
|
r->h->release_read_buffer(r);
|
2006-10-13 04:39:03 +00:00
|
|
|
} else {
|
|
|
|
assert(r->error == EDOM);
|
2006-10-17 03:28:24 +00:00
|
|
|
r->h->release_read_buffer(r);
|
2006-10-13 04:39:03 +00:00
|
|
|
assert(h->start_position(h) > offsets[val]);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
};
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
}
|
2007-10-23 01:51:03 +00:00
|
|
|
// Force 1% of the time.
|
|
|
|
if(!myrandom(100)) {
|
|
|
|
h->force(h);
|
|
|
|
}
|
2006-10-13 04:39:03 +00:00
|
|
|
|
|
|
|
// Truncate 1% of the time.
|
2007-10-23 23:26:33 +00:00
|
|
|
if(!myrandom(100) && handle_truncate_is_supported) {
|
2006-10-13 04:39:03 +00:00
|
|
|
lsn_t pre_start = h->start_position(h);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
pthread_mutex_lock(&trunc_mut);
|
|
|
|
lsn_t start = trunc_val;
|
|
|
|
lsn_t stop = start - 100 + myrandom(200);
|
2009-04-14 20:21:05 +00:00
|
|
|
if(stop > trunc_val) {
|
2006-10-13 04:39:03 +00:00
|
|
|
trunc_val = stop;
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&trunc_mut);
|
|
|
|
|
|
|
|
assert(pre_start <= start);
|
|
|
|
int ret = h->truncate_start(h, stop);
|
2009-04-14 20:21:05 +00:00
|
|
|
if(!ret) {
|
2006-10-13 04:39:03 +00:00
|
|
|
lsn_t post_stop = h->start_position(h);
|
|
|
|
assert(stop <= post_stop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(offsets);
|
|
|
|
}
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
void handle_sequentialtest(stasis_handle_t * h) {
|
2007-10-23 01:51:03 +00:00
|
|
|
time_t seed = time(0);
|
2007-10-22 20:48:12 +00:00
|
|
|
printf("Seed = %ld\n", seed);
|
2006-10-13 04:39:03 +00:00
|
|
|
srandom(seed);
|
|
|
|
|
|
|
|
int * values = malloc(VALUE_COUNT * sizeof(int));
|
|
|
|
|
|
|
|
for(int i = 0; i < VALUE_COUNT; i++) {
|
|
|
|
values[i] = i;
|
|
|
|
}
|
|
|
|
trunc_val = 0;
|
|
|
|
thread_arg arg = { values, VALUE_COUNT, h};
|
|
|
|
load_handle(&arg);
|
|
|
|
|
|
|
|
free(values);
|
|
|
|
}
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
void handle_concurrencytest(stasis_handle_t * h) {
|
2006-10-13 04:39:03 +00:00
|
|
|
int vc = myrandom(VALUE_COUNT) + 10;
|
|
|
|
|
2006-10-17 03:28:24 +00:00
|
|
|
printf("Running concurrency test with %d values", vc); fflush(stdout);
|
2006-10-13 04:39:03 +00:00
|
|
|
|
|
|
|
int * values = malloc(vc * sizeof(int));
|
|
|
|
|
|
|
|
for(int i = 0; i < vc; i++) {
|
|
|
|
values[i] = i;
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
thread_arg * args = malloc(THREAD_COUNT * sizeof(thread_arg));
|
|
|
|
pthread_t * threads = malloc(THREAD_COUNT * sizeof(pthread_t));
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-13 04:39:03 +00:00
|
|
|
int val_per_thread = vc / THREAD_COUNT;
|
|
|
|
trunc_val = 0;
|
|
|
|
for(int i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
args[i].values = &(values[i * val_per_thread]);
|
|
|
|
args[i].count = val_per_thread;
|
|
|
|
args[i].h = h;
|
|
|
|
pthread_create(&threads[i], 0, (void*(*)(void*))load_handle, &args[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
pthread_join(threads[i], 0);
|
|
|
|
}
|
|
|
|
free(values);
|
|
|
|
free(args);
|
|
|
|
free(threads);
|
|
|
|
}
|
|
|
|
/**
|
2009-04-14 20:21:05 +00:00
|
|
|
@test
|
2006-10-13 04:39:03 +00:00
|
|
|
Check the memory I/O handle.
|
|
|
|
*/
|
|
|
|
START_TEST(io_memoryTest) {
|
2007-10-22 20:48:12 +00:00
|
|
|
printf("io_memoryTest\n"); fflush(stdout);
|
2006-10-17 03:28:24 +00:00
|
|
|
stasis_handle_t * h;
|
2006-10-26 05:48:30 +00:00
|
|
|
h = stasis_handle(open_memory)(0);
|
2006-10-17 03:28:24 +00:00
|
|
|
// h = stasis_handle(open_debug)(h);
|
2006-10-13 04:39:03 +00:00
|
|
|
handle_smoketest(h);
|
|
|
|
h->close(h);
|
2006-10-26 05:48:30 +00:00
|
|
|
h = stasis_handle(open_memory)(0);
|
2006-10-17 03:28:24 +00:00
|
|
|
// h = stasis_handle(open_debug)(h);
|
2006-10-13 04:39:03 +00:00
|
|
|
handle_sequentialtest(h);
|
|
|
|
h->close(h);
|
2006-10-26 05:48:30 +00:00
|
|
|
h = stasis_handle(open_memory)(0);
|
2006-10-17 03:28:24 +00:00
|
|
|
// h = stasis_handle(open_debug)(h);
|
2006-10-13 04:39:03 +00:00
|
|
|
handle_concurrencytest(h);
|
|
|
|
h->close(h);
|
|
|
|
} END_TEST
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
START_TEST(io_fileTest) {
|
2007-10-22 20:48:12 +00:00
|
|
|
printf("io_fileTest\n"); fflush(stdout);
|
2006-10-18 00:57:36 +00:00
|
|
|
stasis_handle_t * h;
|
2006-10-26 05:48:30 +00:00
|
|
|
h = stasis_handle(open_file)(0, "logfile.txt", O_CREAT | O_RDWR, FILE_PERM);
|
|
|
|
// h = stasis_handle(open_debug)(h);
|
|
|
|
handle_smoketest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
|
|
|
h = stasis_handle(open_file)(0, "logfile.txt", O_CREAT | O_RDWR, FILE_PERM);
|
|
|
|
//h = stasis_handle(open_debug)(h);
|
|
|
|
handle_sequentialtest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
|
|
|
h = stasis_handle(open_file)(0, "logfile.txt", O_CREAT | O_RDWR, FILE_PERM);
|
2007-08-20 16:23:57 +00:00
|
|
|
//handle_concurrencytest(h);
|
2006-10-26 05:48:30 +00:00
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
|
|
|
} END_TEST
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
static stasis_handle_t * fast_factory(lsn_t off, lsn_t len, void * ignored) {
|
2006-10-26 05:48:30 +00:00
|
|
|
stasis_handle_t * h = stasis_handle(open_memory)(off);
|
|
|
|
// h = stasis_handle(open_debug)(h);
|
|
|
|
stasis_write_buffer_t * w = h->append_buffer(h, len);
|
|
|
|
w->h->release_write_buffer(w);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-26 05:48:30 +00:00
|
|
|
return h;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-26 05:48:30 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 16:23:57 +00:00
|
|
|
START_TEST(io_pfileTest) {
|
2007-10-22 20:48:12 +00:00
|
|
|
printf("io_pfileTest\n"); fflush(stdout);
|
2007-10-23 23:26:33 +00:00
|
|
|
handle_truncate_is_supported = 0;
|
2007-08-20 16:23:57 +00:00
|
|
|
|
|
|
|
stasis_handle_t * h;
|
|
|
|
h = stasis_handle(open_pfile)(0, "logfile.txt", O_CREAT | O_RDWR, FILE_PERM);
|
|
|
|
// h = stasis_handle(open_debug)(h);
|
|
|
|
handle_smoketest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
|
|
|
h = stasis_handle(open_pfile)(0, "logfile.txt", O_CREAT | O_RDWR, FILE_PERM);
|
|
|
|
//h = stasis_handle(open_debug)(h);
|
|
|
|
handle_sequentialtest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
|
|
|
h = stasis_handle(open_pfile)(0, "logfile.txt", O_CREAT | O_RDWR, FILE_PERM);
|
|
|
|
//handle_concurrencytest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
2007-10-23 23:26:33 +00:00
|
|
|
handle_truncate_is_supported = 1;
|
2007-08-20 16:23:57 +00:00
|
|
|
} END_TEST
|
|
|
|
|
2006-10-28 03:33:02 +00:00
|
|
|
typedef struct sf_args {
|
|
|
|
char * filename;
|
|
|
|
int openMode;
|
|
|
|
int filePerm;
|
|
|
|
} sf_args;
|
|
|
|
|
2010-01-06 23:44:07 +00:00
|
|
|
static stasis_handle_t * slow_factory_file(void * argsP) {
|
2006-10-28 03:33:02 +00:00
|
|
|
sf_args * args = (sf_args*) argsP;
|
|
|
|
return stasis_handle(open_file)(0, args->filename, args->openMode, args->filePerm);
|
|
|
|
}
|
2010-01-06 23:44:07 +00:00
|
|
|
static stasis_handle_t * slow_factory_pfile(void * argsP) {
|
|
|
|
sf_args * args = (sf_args*) argsP;
|
|
|
|
return stasis_handle(open_pfile)(0, args->filename, args->openMode, args->filePerm);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(io_nonBlockingTest_file) {
|
|
|
|
printf("io_nonBlockingTest\n"); fflush(stdout);
|
|
|
|
stasis_handle_t * h;
|
|
|
|
|
|
|
|
sf_args slow_args = {
|
|
|
|
"logfile.txt",
|
|
|
|
O_CREAT | O_RDWR,
|
|
|
|
FILE_PERM
|
|
|
|
};
|
|
|
|
|
|
|
|
h = stasis_handle(open_non_blocking)(slow_factory_file, 0, &slow_args, 0,
|
|
|
|
fast_factory, 0,
|
|
|
|
5, 1024*1024, 100);
|
|
|
|
// h = stasis_handle(open_debug)(h);
|
|
|
|
handle_smoketest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
|
|
|
h = stasis_handle(open_non_blocking)(slow_factory_file, 0, &slow_args, 0,
|
|
|
|
fast_factory, 0,
|
|
|
|
5, 1024*1024, 100);
|
|
|
|
//h = stasis_handle(open_debug)(h);
|
|
|
|
handle_sequentialtest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
|
|
|
h = stasis_handle(open_non_blocking)(slow_factory_file, 0, &slow_args, 0,
|
|
|
|
fast_factory, 0,
|
|
|
|
5, 1024 * 1024, 100);
|
|
|
|
handle_concurrencytest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
|
|
|
} END_TEST
|
|
|
|
|
2006-10-28 03:33:02 +00:00
|
|
|
|
2010-01-06 23:44:07 +00:00
|
|
|
START_TEST(io_nonBlockingTest_pfile) {
|
2007-10-22 20:48:12 +00:00
|
|
|
printf("io_nonBlockingTest\n"); fflush(stdout);
|
2006-10-26 05:48:30 +00:00
|
|
|
stasis_handle_t * h;
|
|
|
|
|
2006-10-28 03:33:02 +00:00
|
|
|
sf_args slow_args = {
|
|
|
|
"logfile.txt",
|
2009-04-14 20:21:05 +00:00
|
|
|
O_CREAT | O_RDWR,
|
2006-10-28 03:33:02 +00:00
|
|
|
FILE_PERM
|
|
|
|
};
|
|
|
|
|
2010-01-06 23:44:07 +00:00
|
|
|
h = stasis_handle(open_non_blocking)(slow_factory_pfile, 0, &slow_args, 0,
|
2006-10-28 03:33:02 +00:00
|
|
|
fast_factory, 0,
|
2006-11-21 06:49:16 +00:00
|
|
|
5, 1024*1024, 100);
|
2006-10-18 00:57:36 +00:00
|
|
|
// h = stasis_handle(open_debug)(h);
|
|
|
|
handle_smoketest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
2010-01-06 23:44:07 +00:00
|
|
|
h = stasis_handle(open_non_blocking)(slow_factory_pfile, 0, &slow_args, 0,
|
2007-10-23 01:51:03 +00:00
|
|
|
fast_factory, 0,
|
2006-11-21 06:49:16 +00:00
|
|
|
5, 1024*1024, 100);
|
2006-10-18 00:57:36 +00:00
|
|
|
//h = stasis_handle(open_debug)(h);
|
|
|
|
handle_sequentialtest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
2010-01-06 23:44:07 +00:00
|
|
|
h = stasis_handle(open_non_blocking)(slow_factory_pfile, 0, &slow_args, 0,
|
2007-10-23 01:51:03 +00:00
|
|
|
fast_factory, 0,
|
2006-11-21 06:49:16 +00:00
|
|
|
5, 1024 * 1024, 100);
|
2006-10-18 00:57:36 +00:00
|
|
|
handle_concurrencytest(h);
|
|
|
|
h->close(h);
|
|
|
|
|
|
|
|
unlink("logfile.txt");
|
|
|
|
|
|
|
|
} END_TEST
|
2006-10-13 04:39:03 +00:00
|
|
|
|
2006-10-26 05:48:30 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
/**
|
2006-10-13 04:39:03 +00:00
|
|
|
Add suite declarations here
|
|
|
|
*/
|
|
|
|
Suite * check_suite(void) {
|
|
|
|
Suite *s = suite_create("io");
|
|
|
|
/* Begin a new test */
|
|
|
|
TCase *tc = tcase_create("io_test");
|
2009-08-08 07:50:06 +00:00
|
|
|
// tcase_set_timeout(tc, 1800); // thirty minute timeout
|
2006-10-13 04:39:03 +00:00
|
|
|
|
|
|
|
/* Sub tests are added, one per line, here */
|
2006-11-22 05:03:32 +00:00
|
|
|
tcase_add_test(tc, io_memoryTest);
|
|
|
|
tcase_add_test(tc, io_fileTest);
|
2007-08-20 16:23:57 +00:00
|
|
|
tcase_add_test(tc, io_pfileTest);
|
2010-01-06 23:44:07 +00:00
|
|
|
tcase_add_test(tc, io_nonBlockingTest_file);
|
|
|
|
(void)io_nonBlockingTest_pfile; // XXX fails due to bug in test (or in pfile?)
|
|
|
|
// tcase_add_test(tc, io_nonBlockingTest_pfile);
|
2006-10-13 04:39:03 +00:00
|
|
|
/* --------------------------------------------- */
|
|
|
|
tcase_add_checked_fixture(tc, setup, teardown);
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "../check_setup.h"
|