Giter VIP home page Giter VIP logo

cs111-lab1's Introduction

CS 111 Lab 1b  Test Cases & Features 

---------------------------------------------------------------
Test Case 1
# Check SEQUENCE command type. 
# The second part should not be executed until the first finishes.
ls -a > foo.txt
cat foo.txt || echo failed!

Similar case:
# Only if the execution order is correct can “CS111” be seen on the screen. 
touch newfile.txt; echo CS111; cat newfile.txt

---------------------------------------------------------------
Test Case 2
# Check AND command type.
# Since bar.txt does not exist, the left command fails and the right
# command will not be executed. Outputs of “ls” will not be seen. 
cat bar.txt && ls

---------------------------------------------------------------
Test Case 3
# Check OR command type
# Since bar.txt does not exist, the left command fails and the right
# command will then be tried.
# Outputs of “ls” can be seen. 
cat bar.txt || ls

---------------------------------------------------------------
Test Case 4
# Check PIPE command type
# “wc” will count the number of lines in the outputs of “ls -a”
ls -a | wc

---------------------------------------------------------------
Test Case 5
# Check SUBSHELL command type and multiple pipes within it 
(sort < a.txt | cat b.txt - | tr A-Z a-z > c.txt
sort -k2 d.txt - < a.txt | uniq -c > e.txt
diff a.txt c.txt > f.txt)

---------------------------------------------------------------
Test Case 6
# Check SIMPLE command type (I/O Redirection)
# Note that foo.txt must exist before this command is executed
# if foo.txt does not exist, should report error
cat < foo.txt > blah.txt

---------------------------------------------------------------
Test Case 7
# More than one '\n' is the same as one '\n' in subshell
# Should not threat them as creating a new tree
(echo hello

echo hey)

---------------------------------------------------------------
Test Case 8
# More than one '\n' is ok after && and ||
echo hello &&

echo hey

---------------------------------------------------------------
Implementation: 
Whenever the parent process receives a command, it will call fork() to
initiate a new child process to take care of that execution request.
Then parent process stops runing until the waited child exits.


For each command, we check its type before its execution:
case SIMPLE_COMMAND:
We simply execute this command. The exit status of the this simple
command will be returned.

case PIPE_COMMAND:
A parent process calls pipe() to create a unidirectional data channel
that can be used for interprocess communication.
Children call dup2() so that they can either write to the write end or
read from the read end of the pipe.
The exit status of the last command in the pipe will be returned. 

case AND_COMMAND:
First we check the exit status of the left command. The right command
will not be executed if the first one fails.

case OR_COMMAND:
First we check the exit status of the left command. The right command
will not be executed if the first one succeeds.

case SUBSHELL_COMMAND:
We execute the subshell command. Its exit status will be returned.

case SEQUENCE_COMMAND: 
By calling waitpid(left, &child_status, 0) in the parent process, we
make sure that a right command will never be executed until the left
one finishes.  The exit status of the last command in the sequence
will be returned.

cs111-lab1's People

Contributors

appletreeisyellow avatar kexinyu avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.