add layer0 test

This commit is contained in:
Victor 2023-11-03 17:47:32 -07:00
parent 2316b93ff0
commit e38810caf3
2 changed files with 35 additions and 6 deletions

View File

@ -1,10 +1,11 @@
set(TARGET_NAME run_tests)
set(TARGET_LAYER0 test_layer0)
# add test sources here ...
add_executable(${TARGET_NAME}
add_executable(${TARGET_LAYER0}
# add need lib and source code here
layer0.cpp
)
../lib/fischl.cpp
testfischl.cpp
)
# add test to activate ctest -VV
add_test(NAME ${TARGET_LAYER0} COMMAND sudo ./${TARGET_LAYER0})

28
test/layer0.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "rawdisk.h"
int main() {
char *d = strdup("/dev/vdb");
RawDisk *H = new RawDisk(d);
char *buf = "iloveosdfjlseirfnerig";
char readBuffer[512] = {0}; // Initialize to zeros
//printf("dir %s, numSectors %lld, diskSize %lld \n", H->dir, H->numSectors, H->diskSize);
//use number to substitute H->getnumSector(), getnumSectors() are not yest implemented
for(off_t i = 0; i < 10; i++) {
H->rawdisk_write(i, buf);
}
//use number to substitute H->getnumSector(), getnumSectors() are not yest implemented
for(off_t i = 0; i < 10; i++) {
H->rawdisk_read(i, readBuffer);
assert(strncmp(readBuffer, buf, strlen(buf)) == 0);
}
delete H; // Delete the RawDisk object
return 0;
}