-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
haukurr11
committed
Feb 18, 2013
0 parents
commit 58e091b
Showing
31 changed files
with
1,488 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# Makefile for the CS:APP Shell Lab | ||
|
||
TEAM = $(shell egrep '^ *\* *Group:' tsh.c | sed -e 's/\*//g' -e 's/ *Group: *//g' | sed 's/ *\([^ ].*\) *$$/\1/g') | ||
USER_1 = $(shell egrep '^ *\* *User 1:' tsh.c | sed -e 's/\*//g' -e 's/ *User 1: *//g' | sed 's/ *\([^ ].*\) *$$/\1/g') | ||
USER_2 = $(shell egrep '^ *\* *User 2:' tsh.c | sed -e 's/\*//g' -e 's/ *User 2: *//g' | sed 's/ *\([^ ].*\) *$$/\1/g') | ||
|
||
ifeq "$(TEAM)" "" | ||
TEAM = "NONE" | ||
endif | ||
ifeq "$(USER_1)" "" | ||
USER_1 = "NONE" | ||
endif | ||
ifeq "$(USER_2)" "" | ||
USER_2 = "NONE" | ||
endif | ||
|
||
VERSION = 1 | ||
HANDINDIR = /labs/shlab/handin | ||
DRIVER = ./sdriver.pl | ||
TSH = ./tsh | ||
TSHREF = ./tshref | ||
TSHARGS = "-p" | ||
CC = gcc | ||
CFLAGS = -Wall -O2 | ||
FILES = $(TSH) ./myspin ./mysplit ./mystop ./myint | ||
|
||
all: $(FILES) | ||
|
||
################## | ||
# Handin your work | ||
################## | ||
handin: | ||
@echo "Team: \"$(TEAM)\"" | ||
@echo "User 1: \"$(USER_1)\"" | ||
@echo "User 2: \"$(USER_2)\"" | ||
@if [ "$(TEAM)" == "NONE" ]; then echo "Team name missing, please add it to the tsh.c file."; exit 1; fi | ||
@if [ "$(USER_1)" != "NONE" ]; then getent passwd $(USER_1) > /dev/null; if [ $$? -ne 0 ]; then echo "User $(USER_1) does not exceist on Skel."; exit 2; fi; fi | ||
@if [ "$(USER_2)" != "NONE" ]; then getent passwd $(USER_2) > /dev/null; if [ $$? -ne 0 ]; then echo "User $(USER_2) does not exceist on Skel."; exit 3; fi; fi | ||
cp tsh.c "$(HANDINDIR)/$(USER)/$(TEAM)-$(VERSION)-tsh.c" | ||
|
||
################## | ||
# Regression tests | ||
################## | ||
|
||
# Run tests using the student's shell program | ||
test01: | ||
$(DRIVER) -t trace01.txt -s $(TSH) -a $(TSHARGS) | ||
test02: | ||
$(DRIVER) -t trace02.txt -s $(TSH) -a $(TSHARGS) | ||
test03: | ||
$(DRIVER) -t trace03.txt -s $(TSH) -a $(TSHARGS) | ||
test04: | ||
$(DRIVER) -t trace04.txt -s $(TSH) -a $(TSHARGS) | ||
test05: | ||
$(DRIVER) -t trace05.txt -s $(TSH) -a $(TSHARGS) | ||
test06: | ||
$(DRIVER) -t trace06.txt -s $(TSH) -a $(TSHARGS) | ||
test07: | ||
$(DRIVER) -t trace07.txt -s $(TSH) -a $(TSHARGS) | ||
test08: | ||
$(DRIVER) -t trace08.txt -s $(TSH) -a $(TSHARGS) | ||
test09: | ||
$(DRIVER) -t trace09.txt -s $(TSH) -a $(TSHARGS) | ||
test10: | ||
$(DRIVER) -t trace10.txt -s $(TSH) -a $(TSHARGS) | ||
test11: | ||
$(DRIVER) -t trace11.txt -s $(TSH) -a $(TSHARGS) | ||
test12: | ||
$(DRIVER) -t trace12.txt -s $(TSH) -a $(TSHARGS) | ||
test13: | ||
$(DRIVER) -t trace13.txt -s $(TSH) -a $(TSHARGS) | ||
test14: | ||
$(DRIVER) -t trace14.txt -s $(TSH) -a $(TSHARGS) | ||
test15: | ||
$(DRIVER) -t trace15.txt -s $(TSH) -a $(TSHARGS) | ||
test16: | ||
$(DRIVER) -t trace16.txt -s $(TSH) -a $(TSHARGS) | ||
|
||
# Run the tests using the reference shell program | ||
rtest01: | ||
$(DRIVER) -t trace01.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest02: | ||
$(DRIVER) -t trace02.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest03: | ||
$(DRIVER) -t trace03.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest04: | ||
$(DRIVER) -t trace04.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest05: | ||
$(DRIVER) -t trace05.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest06: | ||
$(DRIVER) -t trace06.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest07: | ||
$(DRIVER) -t trace07.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest08: | ||
$(DRIVER) -t trace08.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest09: | ||
$(DRIVER) -t trace09.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest10: | ||
$(DRIVER) -t trace10.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest11: | ||
$(DRIVER) -t trace11.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest12: | ||
$(DRIVER) -t trace12.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest13: | ||
$(DRIVER) -t trace13.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest14: | ||
$(DRIVER) -t trace14.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest15: | ||
$(DRIVER) -t trace15.txt -s $(TSHREF) -a $(TSHARGS) | ||
rtest16: | ||
$(DRIVER) -t trace16.txt -s $(TSHREF) -a $(TSHARGS) | ||
|
||
|
||
# clean up | ||
clean: | ||
rm -f $(FILES) *.o *~ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
################ | ||
CS:APP Shell Lab | ||
################ | ||
|
||
Files: | ||
|
||
Makefile # Compiles your shell program and runs the tests | ||
README # This file | ||
tsh.c # The shell program that you will write and hand in | ||
tshref # The reference shell binary. | ||
|
||
# The remaining files are used to test your shell | ||
sdriver.pl # The trace-driven shell driver | ||
trace*.txt # The 15 trace files that control the shell driver | ||
tshref.out # Example output of the reference shell on all 15 traces | ||
|
||
# Little C programs that are called by the trace files | ||
myspin.c # Takes argument <n> and spins for <n> seconds | ||
mysplit.c # Forks a child that spins for <n> seconds | ||
mystop.c # Spins for <n> seconds and sends SIGTSTP to itself | ||
myint.c # Spins for <n> seconds and sends SIGINT to itself | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* myint.c - Another handy routine for testing your tiny shell | ||
* | ||
* usage: myint <n> | ||
* Sleeps for <n> seconds and sends SIGINT to itself. | ||
* | ||
*/ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
#include <signal.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int i, secs; | ||
pid_t pid; | ||
|
||
if (argc != 2) { | ||
fprintf(stderr, "Usage: %s <n>\n", argv[0]); | ||
exit(0); | ||
} | ||
secs = atoi(argv[1]); | ||
|
||
for (i=0; i < secs; i++) | ||
sleep(1); | ||
|
||
pid = getpid(); | ||
|
||
if (kill(pid, SIGINT) < 0) | ||
fprintf(stderr, "kill (int) error"); | ||
|
||
exit(0); | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* myspin.c - A handy program for testing your tiny shell | ||
* | ||
* usage: myspin <n> | ||
* Sleeps for <n> seconds in 1-second chunks. | ||
* | ||
*/ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int i, secs; | ||
|
||
if (argc != 2) { | ||
fprintf(stderr, "Usage: %s <n>\n", argv[0]); | ||
exit(0); | ||
} | ||
secs = atoi(argv[1]); | ||
for (i=0; i < secs; i++) | ||
sleep(1); | ||
exit(0); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* mysplit.c - Another handy routine for testing your tiny shell | ||
* | ||
* usage: mysplit <n> | ||
* Fork a child that spins for <n> seconds in 1-second chunks. | ||
*/ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
#include <signal.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int i, secs; | ||
|
||
if (argc != 2) { | ||
fprintf(stderr, "Usage: %s <n>\n", argv[0]); | ||
exit(0); | ||
} | ||
secs = atoi(argv[1]); | ||
|
||
|
||
if (fork() == 0) { /* child */ | ||
for (i=0; i < secs; i++) | ||
sleep(1); | ||
exit(0); | ||
} | ||
|
||
/* parent waits for child to terminate */ | ||
wait(NULL); | ||
|
||
exit(0); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* mystop.c - Another handy routine for testing your tiny shell | ||
* | ||
* usage: mystop <n> | ||
* Sleeps for <n> seconds and sends SIGTSTP to itself. | ||
* | ||
*/ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
#include <signal.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int i, secs; | ||
pid_t pid; | ||
|
||
if (argc != 2) { | ||
fprintf(stderr, "Usage: %s <n>\n", argv[0]); | ||
exit(0); | ||
} | ||
secs = atoi(argv[1]); | ||
|
||
for (i=0; i < secs; i++) | ||
sleep(1); | ||
|
||
pid = getpid(); | ||
|
||
if (kill(-pid, SIGTSTP) < 0) | ||
fprintf(stderr, "kill (tstp) error"); | ||
|
||
exit(0); | ||
|
||
} |
Oops, something went wrong.