test-coffee: Fix the garbage collection test
This test could sometimes fail because of a lack of free contiguous pages in the file system. Fix this by removing the created files at the end of each test. Besides, the test files do not have to be removed at the beginning of each test since the file system is initially formatted. Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
This commit is contained in:
parent
003b4b0d63
commit
6df2b91a31
|
@ -60,8 +60,6 @@ coffee_test_basic(void)
|
||||||
unsigned char buf[256];
|
unsigned char buf[256];
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
cfs_remove("T1");
|
|
||||||
|
|
||||||
wfd = rfd = afd = -1;
|
wfd = rfd = afd = -1;
|
||||||
|
|
||||||
for(r = 0; r < sizeof(buf); r++) {
|
for(r = 0; r < sizeof(buf); r++) {
|
||||||
|
@ -187,6 +185,7 @@ coffee_test_basic(void)
|
||||||
end:
|
end:
|
||||||
cfs_close(wfd);
|
cfs_close(wfd);
|
||||||
cfs_close(rfd);
|
cfs_close(rfd);
|
||||||
|
cfs_remove("T1");
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -200,8 +199,6 @@ coffee_test_append(void)
|
||||||
#define APPEND_BYTES 1000
|
#define APPEND_BYTES 1000
|
||||||
#define BULK_SIZE 10
|
#define BULK_SIZE 10
|
||||||
|
|
||||||
cfs_remove("T2");
|
|
||||||
|
|
||||||
/* Test 1 and 2: Append data to the same file many times. */
|
/* Test 1 and 2: Append data to the same file many times. */
|
||||||
for(i = 0; i < APPEND_BYTES; i += BULK_SIZE) {
|
for(i = 0; i < APPEND_BYTES; i += BULK_SIZE) {
|
||||||
afd = cfs_open("T2", CFS_WRITE | CFS_APPEND);
|
afd = cfs_open("T2", CFS_WRITE | CFS_APPEND);
|
||||||
|
@ -244,6 +241,7 @@ coffee_test_append(void)
|
||||||
error = 0;
|
error = 0;
|
||||||
end:
|
end:
|
||||||
cfs_close(afd);
|
cfs_close(afd);
|
||||||
|
cfs_remove("T2");
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -256,7 +254,6 @@ coffee_test_modify(void)
|
||||||
int r, i;
|
int r, i;
|
||||||
unsigned offset;
|
unsigned offset;
|
||||||
|
|
||||||
cfs_remove("T3");
|
|
||||||
wfd = -1;
|
wfd = -1;
|
||||||
|
|
||||||
if(cfs_coffee_reserve("T3", FILE_SIZE) < 0) {
|
if(cfs_coffee_reserve("T3", FILE_SIZE) < 0) {
|
||||||
|
@ -310,6 +307,7 @@ coffee_test_modify(void)
|
||||||
error = 0;
|
error = 0;
|
||||||
end:
|
end:
|
||||||
cfs_close(wfd);
|
cfs_close(wfd);
|
||||||
|
cfs_remove("T3");
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -318,21 +316,17 @@ coffee_test_gc(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
cfs_remove("alpha");
|
|
||||||
cfs_remove("beta");
|
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < 100; i++) {
|
for (i = 0; i < 100; i++) {
|
||||||
if (i & 1) {
|
if (i & 1) {
|
||||||
if(cfs_coffee_reserve("alpha", random_rand() & 0xffff) < 0) {
|
if(cfs_coffee_reserve("beta", random_rand() & 0xffff) < 0) {
|
||||||
return i;
|
|
||||||
}
|
|
||||||
cfs_remove("beta");
|
|
||||||
} else {
|
|
||||||
if(cfs_coffee_reserve("beta", 93171) < 0) {
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
cfs_remove("alpha");
|
cfs_remove("alpha");
|
||||||
|
} else {
|
||||||
|
if(cfs_coffee_reserve("alpha", 93171) < 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
cfs_remove("beta");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue