Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

you are on the testing team at work. unfortunately, your company's programmers do not have good testing practices. there aren't many tests written, and

image text in transcribedimage text in transcribed

you are on the testing team at work. unfortunately, your company's programmers do not have good testing practices. there aren't many tests written, and the ones that are out there don't work reliably: they pass some of the time, but they often fail for unrelated reasons. while your developers get their testing act together, your boss wants you to write a tool to at least make the tests relatively usable. you have to write an unflake program that will rerun a test if it fails the first time (or the 2nd time or 3rd time...). failing means it did not exit with a 0 exit code. unflake will keep track of stdout, stderr, and the exit code of the program. if the unflake is able to run the program successfully, it will print the stdout of the successful run to stdout, the stderr of the successful run to stderr, and exit with exit code of 0. Otherwise, it will output the stdout and stderr of the first run of the program and exit with the exit code of that run. if the test program dies due to a signal, use 100+ signal_number as the exit code. the flaky tests sometimes hang, so if a timeout is exceeded, you need to stop the program with a SIGKILL. you will use execvp to execute the program. if execvp fails, use perror passing the name of the test_command and exit with a code of 2. specification unflake max_tries max_timeout test\command args... max_tries - is the maximum amount of times you will try rerunning the test before giving up. max_timeout - the maximum allowed time for a test to run test_command - the command you will be running for the test args - any arguments the test may take you will probably create temporary files to track output. make sure they are deleted before unflake exits. USAGE $ ./unflake USAGE: ./unflake max_tries max_timeout test_command args... max_tries - must be greater than or equal to 1 max_timeout - number of seconds greater than or equal to 1 $ echo $? 1 $ ./unflake not_num not_num cmd asdf USAGE: /unflake max_tries max_timeout test_command args... max_tries must be greater than or equal to 1 max_timeout - number of seconds greater than or equal to 1 $ echo $? 1 calls to use when you implement unflake, you will need to use the following system calls: fork, execvp, wait, open, dup2, signal, kill, and alarm. to get the exit codes from that status returned from wait please look at the macros (they act like functions) in the man page for wait (man 2 wait). when you open a file with create, you will need to set the mode, so you will probably invoke it like: open (name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR) Compiling Your Code gcc -g -std-gnu2x -Wall -o unflake unflake.c Examples Command to RUN: ./runvalgrind.sh ./unflake Expected Exit Code: 1 USAGE: ./unflake max_tries max_timeout test_command args... max_tries must be greater than or equal to 1. max_timeout number of seconds greater than or equal to 1. Command to RUN: ./runvalgrind.sh ./unflake 1 1 echo hi Expected Exit Code: 0 hi Command to RUN: ./runvalgrind.sh ./unflake 1 1 badcmd the command is invalid Expected Exit Code: 2 badcmd: No such file or directory Command to RUN: ./runvalgrind.sh ./unflake 3 3 sleep 2 Expected Exit Code: 0 Command to RUN: ./unflake 1 1 sleep 2. Expected Exit Code: 109. Suggested Steps implement the usage message implement the max_tries and max_timeout argument processing. use fork and execvp to run the test code use wait and related macros to get the exit code collect stdout and stderr into a file using open and dup2. read from those files and write to stdout and stderr and delete the files before exiting unflake. implement timeouts using alarm and signal add a loop to retry if the exit code is not successful.

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_2

Step: 3

blur-text-image_3

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

Auditing a risk based approach to conducting a quality audit

Authors: Karla Johnstone, Audrey Gramling, Larry Rittenberg

9th edition

9781133939160, 1133939155, 1133939163, 978-1133939153

More Books

Students also viewed these Programming questions

Question

Draw and name the eight isomeric alcohols with formula C5H12O.

Answered: 1 week ago