Merge pull request #6 from SuperconductZB/victortung

add layer0 test
This commit is contained in:
FactorialN 2023-11-05 13:04:31 -08:00 committed by GitHub
commit a1b6298a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 7 deletions

View File

@ -1,10 +1,11 @@
set(TARGET_NAME run_tests)
set(TARGET_LAYER0 test_layer0)
set(DIR_PLACE /dev/vdb)
# 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} ${DIR_PLACE})

34
test/layer0.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "rawdisk.h"
int main(int argc, char *argv[]) {
char *d = NULL;
if(argc < 2){
d = strdup("/dev/vdc");
}else{
d = argv[1];
}
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;
}