Answered step by step
Verified Expert Solution
Link Copied!

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 TESTER_ARGUMENTS "hw:"
#define USAGE \
"USAGE: test [-h][-w workload-file]
"\
"
"\
"where:
"\
"-h - help mode (display this message)
"\
"
"\
/* Test functions. */
int test_mount_unmount();
int test_read_before_mount();
int test_read_invalid_parameters();
int test_read_within_block();
int test_read_across_blocks();
int test_read_three_blocks();
int test_read_across_disks();
/* New test functions for the assignment 3.*/
int test_write_before_mount();
int test_write_before_permission();
int test_write_invalid_parameters();
int test_write_within_block();
int test_write_across_blocks();
int test_write_three_blocks();
int test_write_across_disks();
/* Utility functions. */
char *stringify(const uint8_t *buf, int length){
char *p =(char *)malloc(length *6);
for (int i =0, n =0; i < length; ++i){
if (i && i %16==0)
n += sprintf(p + n,"
");
n += sprintf(p + n,"0x%02x ", buf[i]);
}
return p;
}
int run_workload(char *workload);
int main(int argc, char *argv[])
{
int ch;
char *workload = NULL;
while ((ch = getopt(argc, argv, TESTER_ARGUMENTS))!=-1){
switch (ch){
case 'h':
fprintf(stderr, USAGE);
return 0;
case 'w':
workload = optarg;
break;
default:
fprintf(stderr, "Unknown command line option (%c), aborting.
", ch);
return -1;
}
}
if (workload){
run_workload(workload);
return 0;
}
int score =0;
score += test_mount_unmount();
score += test_read_before_mount();
score += test_read_invalid_parameters();
score += test_read_within_block();
score += test_read_across_blocks();
score += test_read_three_blocks();
score += test_read_across_disks();
score += test_write_before_mount();
score += test_write_before_permission();
score += test_write_invalid_parameters();
score += test_write_within_block();
score += test_write_across_blocks();
score += test_write_three_blocks();
score += test_write_across_disks();
printf("Total score: %d/%d
", score, 18);
return 0;
}
int test_mount_unmount(){
printf("running %s: ",__func__);
int rc = mdadm_mount();
if (rc !=1){
printf("failed: mount should succeed on an unmounted system but it failed.
");
return 0;
}
rc = mdadm_mount();
if (rc ==1){
printf("failed: mount should fail on an already mounted system but it succeeded.
");
return 0;
}
if (rc !=-1){
printf("failed: mount should return -1 on failure but returned %d
", rc);
return 0;
}
rc = mdadm_unmount();
if (rc !=1){
printf("failed: unmount should succeed on a mounted system but it failed.
");
return 0;
}
rc = mdadm_unmount();
if (rc ==1){
printf("failed: unmount should fail on an already unmounted system but it succeeded.
");
return 0;
}
if (rc !=-1){
printf("failed: unmount should return -1 on failure but returned %d
", rc);
return 0;
}
printf("passed
");
return 3;
}
#define SIZE 16
int test_read_before_mount(){
printf("running %s: ",__func__);
uint8_t buf[SIZE];
if (mdadm_read(0, SIZE, buf)!=-1){
printf("failed: read should fail on an umounted system but it did not.
");
return 0;
}
printf("passed
");
return 1;
}
int test_read_invalid_parameters(){
printf("running %s: ",__func__);
mdadm_mount();
bool success = false;
uint8_t buf1[SIZE];
uint32_t addr =0x1fffffff;
if (mdadm_read(addr, SIZE, buf1)!=-1){
printf("failed: read should fail on an out-of-bound linear address but it did not.
");
goto out;
}
addr =1048570;
if (mdadm_read(addr, SIZE, buf1)!=-1){
printf("failed: read should fail if it goes beyond the end of the linear address space but it did not.
");
goto out;
}
uint8_t buf2[2049];
if (mdadm_read(0, sizeof(buf2), buf2)!=-1){
printf("failed: read should fail on larger than 2048-byte I/O sizes but it did not.
");
goto out;
}
if (mdadm_read(0, SIZE, NULL)!=-1){
printf(

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

View feedback as judgmental and uncomfortable

Answered: 1 week ago

Question

What are some of the hiring standards to avoid?

Answered: 1 week ago

Question

What are some metrics for evaluating recruitment and selection?

Answered: 1 week ago