Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #include #include #include #include #include #include #include #include #include #include jbod.h #include mdadm.h #include util.h #include tester.h #define
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "jbod.h
#include "mdadm.h
#include "util.h
#include "tester.h
#define TESTERARGUMENTS hw:
#define USAGE
"USAGE: test hw workloadfile
"where:
h help mode display this message
Test functions.
int testmountunmount;
int testreadbeforemount;
int testreadinvalidparameters;
int testreadwithinblock;
int testreadacrossblocks;
int testreadthreeblocks;
int testreadacrossdisks;
New test functions for the assignment
int testwritebeforemount;
int testwritebeforepermission;
int testwriteinvalidparameters;
int testwritewithinblock;
int testwriteacrossblocks;
int testwritethreeblocks;
int testwriteacrossdisks;
Utility functions.
char stringifyconst uintt buf int length
char p char malloclength ;
for int i n ; i length; i
if i && i
n sprintfp n
;
n sprintfp nxx bufi;
return p;
int runworkloadchar workload;
int mainint argc, char argv
int ch;
char workload NULL;
while ch getoptargc argv, TESTERARGUMENTS
switch ch
case h:
fprintfstderr USAGE;
return ;
case w:
workload optarg;
break;
default:
fprintfstderr "Unknown command line option c aborting.
ch;
return ;
if workload
runworkloadworkload;
return ;
int score ;
score testmountunmount;
score testreadbeforemount;
score testreadinvalidparameters;
score testreadwithinblock;
score testreadacrossblocks;
score testreadthreeblocks;
score testreadacrossdisks;
score testwritebeforemount;
score testwritebeforepermission;
score testwriteinvalidparameters;
score testwritewithinblock;
score testwriteacrossblocks;
score testwritethreeblocks;
score testwriteacrossdisks;
printfTotal score: dd
score, ;
return ;
int testmountunmount
printfrunning s: func;
int rc mdadmmount;
if rc
printffailed: mount should succeed on an unmounted system but it failed.
;
return ;
rc mdadmmount;
if rc
printffailed: mount should fail on an already mounted system but it succeeded.
;
return ;
if rc
printffailed: mount should return on failure but returned d
rc;
return ;
rc mdadmunmount;
if rc
printffailed: unmount should succeed on a mounted system but it failed.
;
return ;
rc mdadmunmount;
if rc
printffailed: unmount should fail on an already unmounted system but it succeeded.
;
return ;
if rc
printffailed: unmount should return on failure but returned d
rc;
return ;
printfpassed
;
return ;
#define SIZE
int testreadbeforemount
printfrunning s: func;
uintt bufSIZE;
if mdadmread SIZE, buf
printffailed: read should fail on an umounted system but it did not.
;
return ;
printfpassed
;
return ;
int testreadinvalidparameters
printfrunning s: func;
mdadmmount;
bool success false;
uintt bufSIZE;
uintt addr xfffffff;
if mdadmreadaddr SIZE, buf
printffailed: read should fail on an outofbound linear address but it did not.
;
goto out;
addr ;
if mdadmreadaddr SIZE, buf
printffailed: read should fail if it goes beyond the end of the linear address space but it did not.
;
goto out;
uintt buf;
if mdadmread sizeofbuf buf
printffailed: read should fail on larger than byte IO sizes but it did not.
;
goto out;
if mdadmread SIZE, NULL
printf
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started