Compare commits

...

1 Commits

6 changed files with 53 additions and 34 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "googletest"]
path = googletest
url = https://github.com/google/googletest.git

View File

@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 14)
include_directories( include_directories(
# fischl include files # fischl include files
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/include
) )
add_executable(fischl add_executable(fischl
@ -17,4 +18,5 @@ add_executable(fischl
) )
enable_testing() enable_testing()
add_subdirectory(test) add_subdirectory(test)
add_subdirectory(googletest)

1
googletest Submodule

@ -0,0 +1 @@
Subproject commit b10fad38c4026a29ea6561ab15fc4818170d1c10

View File

@ -12,6 +12,10 @@ add_executable(${TARGET_LAYER1_API}
layer1_API.cpp layer1_API.cpp
) )
# Link Google Test to your test executables
target_link_libraries(${TARGET_LAYER0} gtest gtest_main)
target_link_libraries(${TARGET_LAYER1_API} gtest gtest_main)
# add test to activate ctest -VV # add test to activate ctest -VV
add_test(NAME ${TARGET_LAYER0} COMMAND sudo ./${TARGET_LAYER0} ${DIR_PLACE}) add_test(NAME ${TARGET_LAYER0} COMMAND sudo ./${TARGET_LAYER0} ${DIR_PLACE})
add_test(NAME ${TARGET_LAYER1_API} COMMAND sudo ./${TARGET_LAYER1_API} ${DIR_PLACE}) add_test(NAME ${TARGET_LAYER1_API} COMMAND sudo ./${TARGET_LAYER1_API} ${DIR_PLACE})

View File

@ -1,29 +1,33 @@
#include <stdio.h> #include <gtest/gtest.h>
#include <string.h>
#include <assert.h>
#include "rawdisk.h" #include "rawdisk.h"
const char* d;
int main(int argc, char *argv[]) { TEST(RawDiskTest, WriteReadTest) {
const char* d = (argc < 2) ? "/dev/vdc" : argv[1];
RawDisk *H = new RawDisk(d); RawDisk *H = new RawDisk(d);
char *buf = "iloveosdfjlseirfnerig"; char *buf = "iloveosdfjlseirfnerig";
char readBuffer[512] = {0}; // Initialize to zeros char readBuffer[512] = {0};
//printf("dir %s, numSectors %lld, diskSize %lld \n", H->dir, H->numSectors, H->diskSize); // Write test
//use number to substitute H->getnumSector(), getnumSectors() are not yest implemented
for(u_int64_t i = 0; i < 10; i++) { for(u_int64_t i = 0; i < 10; i++) {
H->rawdisk_write(i*512, buf, strlen(buf));//Change write_API H->rawdisk_write(i*512, buf, strlen(buf));
}
//use number to substitute H->getnumSector(), getnumSectors() are not yest implemented
for(u_int64_t i = 0; i < 10; i++) {
H->rawdisk_read(i*512, readBuffer, sizeof(readBuffer));//Change read_API
assert(strncmp(readBuffer, buf, strlen(buf)) == 0);
} }
delete H; // Delete the RawDisk object // Read and verify test
for(u_int64_t i = 0; i < 10; i++) {
H->rawdisk_read(i*512, readBuffer, sizeof(readBuffer));
EXPECT_EQ(strncmp(readBuffer, buf, strlen(buf)), 0);
}
return 0; delete H;
}
TEST(RawDiskTest, AssertionFailureTest) {
EXPECT_EQ(2, 3); // Intentional failure
EXPECT_EQ(4, 1); // Another intentional failure
}
int main(int argc, char **argv) {
d = (argc < 2) ? "/dev/vdc" : argv[1];//how to do with this?
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
} }

View File

@ -1,12 +1,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <gtest/gtest.h>
#include "fs.h" #include "fs.h"
#include <inttypes.h> #include <inttypes.h>
int main(int argc, char *argv[]) { const char* d;
const char* d = (argc < 2) ? "/dev/vdc" : argv[1];
TEST(Layer1Test, APItest) {
RawDisk *H = new RawDisk(d); RawDisk *H = new RawDisk(d);
printf("test inode\n"); printf("test inode\n");
@ -20,21 +21,21 @@ int main(int argc, char *argv[]) {
for (int j = 0; j < 8; j++) for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j); t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
assert(t == 2);//the first 1th unused inode will store the next unused inode 2th EXPECT_EQ(t, 2);//the first 1th unused inode will store the next unused inode 2th
//test the number before end of inode 524286th //test the number before end of inode 524286th
H->rawdisk_read((MAX_INODE - 2) * SECTOR_SIZE, buffer, sizeof(buffer)); H->rawdisk_read((MAX_INODE - 2) * SECTOR_SIZE, buffer, sizeof(buffer));
t = 0; t = 0;
for (int j = 0; j < 8; j++) for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j); t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
assert(t == MAX_INODE - 1);//store the maximun th inode EXPECT_EQ(t, MAX_INODE - 1);//store the maximun th inode
//test the end of inode 524287th //test the end of inode 524287th
H->rawdisk_read((MAX_INODE - 1) * SECTOR_SIZE, buffer, sizeof(buffer)); H->rawdisk_read((MAX_INODE - 1) * SECTOR_SIZE, buffer, sizeof(buffer));
t = 0; t = 0;
for (int j = 0; j < 8; j++) for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j); t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
assert(t == 0);//the end of inode(524287th inode) do not have the next inode address EXPECT_EQ(t, 0);//the end of inode(524287th inode) do not have the next inode address
/**************************test datablock Initialization***************************/ /**************************test datablock Initialization***************************/
//we separate 2048 4kB I/O block(1+2047) as a group and the first I/O block will manage the following 2047 I/O block usage. //we separate 2048 4kB I/O block(1+2047) as a group and the first I/O block will manage the following 2047 I/O block usage.
//the first 8 bytes(0~7) in first I/O block store the address of next first I/O block, the following 256(8~263) bytes record 2047 I/O block usage. //the first 8 bytes(0~7) in first I/O block store the address of next first I/O block, the following 256(8~263) bytes record 2047 I/O block usage.
@ -44,14 +45,14 @@ int main(int argc, char *argv[]) {
for (int j = 0; j < 8; j++) for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j); t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
assert(t == (MAX_INODE+2048*8)*SECTOR_SIZE);//the first 8 bytes of 4k I/O block will store the next address(after 2048*4k I/O block) EXPECT_EQ(t, (MAX_INODE+2048*8)*SECTOR_SIZE);//the first 8 bytes of 4k I/O block will store the next address(after 2048*4k I/O block)
//test the end of the datablock //test the end of the datablock
H->rawdisk_read((MAX_BLOCKNUM - 2048*8) * SECTOR_SIZE, buffer, sizeof(buffer)); H->rawdisk_read((MAX_BLOCKNUM - 2048*8) * SECTOR_SIZE, buffer, sizeof(buffer));
t = 0; t = 0;
for (int j = 0; j < 8; j++) for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j); t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
assert(t == (MAX_BLOCKNUM)*SECTOR_SIZE); EXPECT_EQ(t, (MAX_BLOCKNUM)*SECTOR_SIZE);
/***************************test inode de/allocation**********************************/ /***************************test inode de/allocation**********************************/
//when requesting an inode, the inode_allocation will give you the inode number, we use inode_list to store the sequence allocate inode //when requesting an inode, the inode_allocation will give you the inode number, we use inode_list to store the sequence allocate inode
@ -62,7 +63,7 @@ int main(int argc, char *argv[]) {
//printf("Allocate 20 inode num:{"); //printf("Allocate 20 inode num:{");
for(int i=0;i<20;i++){ for(int i=0;i<20;i++){
inode_list[i] = inop.inode_allocate(*H); inode_list[i] = inop.inode_allocate(*H);
assert(inode_list[i] == i+1); EXPECT_EQ(inode_list[i], i+1);
//printf(" %d", inode_list[i]); //printf(" %d", inode_list[i]);
} }
//printf("}\n"); //printf("}\n");
@ -75,7 +76,7 @@ int main(int argc, char *argv[]) {
for(int i=10;i<20;i++){ for(int i=10;i<20;i++){
inode_list[i] = inop.inode_allocate(*H); inode_list[i] = inop.inode_allocate(*H);
//printf("inode %d, rec_f %d\n,", inode_list[i],record_free[rec]); //printf("inode %d, rec_f %d\n,", inode_list[i],record_free[rec]);
assert(inode_list[i] == record_free[rec]); EXPECT_EQ(inode_list[i], record_free[rec]);
rec--; rec--;
} }
printf("}\n"); printf("}\n");
@ -105,7 +106,7 @@ int main(int argc, char *argv[]) {
for(int i=0;i<10;i++){ for(int i=0;i<10;i++){
//printf("%dth data block allocate again addres: ", i); //printf("%dth data block allocate again addres: ", i);
for(int j=0;j<3;j++){ for(int j=0;j<3;j++){
assert(inode_inside[i].datablock_allocate(*H) == rec_datablock_free[i][j]); EXPECT_EQ(inode_inside[i].datablock_allocate(*H), rec_datablock_free[i][j]);
//printf("%d," ,inode_inside[i].datablock_allocate(*H)); //printf("%d," ,inode_inside[i].datablock_allocate(*H));
} }
//printf("\n"); //printf("\n");
@ -113,6 +114,10 @@ int main(int argc, char *argv[]) {
//printf("}\n"); //printf("}\n");
delete H; // Delete the RawDisk object delete H; // Delete the RawDisk object
return 0;
} }
int main(int argc, char **argv) {
d = (argc < 2) ? "/dev/vdc" : argv[1];//how to do with this?
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}