Esempio n. 1
0
def test(cmd):
    global expected
    global got
    util.info("")
    util.info("- Starting " + cmd)
    util.info("")
    util.run(cmd)

    start = time.time()

    # reset for multiple test
    expected = []
    got = []

    for i in range(1, NUM_CLIENT):
        expected.append(commands.getoutput("cat ./testdata/file%s.txt" % str(i)))

    commands.getoutput("rm -rf %s" % tmpfile)
    clientlist = []

    for i in range(0, NUM_CLIENT):
        client = testit("Client-" + str(i), i)
        clientlist.append(client)
        client.start()
        time.sleep(0.3)

    for client in clientlist:
        client.join()


    end = time.time()
    util.info("Elapsed time (in seconds): " + str(end-start))

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected");

    time.sleep(CGI_SPIN_TIME + 2)
    res = commands.getoutput("cat %s" % tmpfile)

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected");

    pos0 = res.find(expected[0])
    pos1 = res.find(expected[1])
    pos2 = res.find(expected[2])
    passed = pos0 > 0 and pos1 > 0 and pos2 > 0 and pos0 < pos1 and pos1 < pos2
    
    util.info(res)
Esempio n. 2
0
def test(cmd):
    global expected
    global got
    global count

    util.info("")
    util.info("- Starting " + cmd)
    util.info("")
    util.run(cmd)
    
    start = time.time()

    clientlist = []
    expected = []
    for i in range(1, NUM_CLIENT):
        expected.append(commands.getoutput("cat ./testdata/file%s.txt" % str(i)))

    commands.getoutput("rm -rf %s" % tmpfile)

    for i in range(0, NUM_CLIENT):
        client = testit("Client-" + str(i), i)
        clientlist.append(client)
        client.start()
        time.sleep(0.3)
    
    for client in clientlist:
        client.join()

    end = time.time()
    util.info("Elapsed time (in seconds): " + str(end-start))

    time.sleep(CGI_SPIN_TIME + 2)
    res = commands.getoutput("cat %s" % tmpfile)

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected");

    pos0 = res.find(expected[0])
    pos1 = res.find(expected[1])
    pos2 = res.find(expected[2])
    passed = pos0 > 0 and pos1 > 0 and pos2 > 0 and pos0 < pos1 and pos1 < pos2
    
    util.info(res)

    if passed:
        print ""
        print "#####################################"
        print "GOOD! you implement SFF correctly"
        print "#####################################"
        print ""
        count = count + 1
    else:
        print ""
        print "#####################################"
        print "Oh oh! ERROR ERROR!"
        print "SFF is not implemented correctly"
        print "#####################################"
        print ""
        sys.exit(-1)
Esempio n. 3
0
def test(cmd):
    print ""
    print "Starting " + cmd
    util.run(cmd)

    clientlist = []

    start = time.time()

    for i in range(0, NUM_CLIENT):
        client = testit("Client-" + str(i))
        client.setDaemon(True)
        clientlist.append(client)
        client.start()

    for client in clientlist:
        client.join()

    end = time.time()

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected")

    print "Elapsed time (in seconds): " + str(end - start)
    if end - start > EXPECTED_TIME:
        util.error("your server is not multithreaded")
Esempio n. 4
0
def test(cmd):
    print ""
    print "Starting " + cmd
    util.run(cmd)

    clientlist = []
    
    start = time.time()

    for i in range(0, NUM_CLIENT):
        client = testit("Client-" + str(i))
        client.setDaemon(True)
        clientlist.append(client)
        client.start()
    
    for client in clientlist:
        client.join()

    end = time.time()

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected");

    print "Elapsed time (in seconds): " + str(end-start)
    if end - start > EXPECTED_TIME:
        util.error("your server is not multithreaded")
Esempio n. 5
0
def test(cmd):
    util.info("")
    util.info("- Starting " + cmd)
    util.info("")
    util.run(cmd)
    
    start = time.time()
    
    clientlist = []

    for i in range(0, NUM_CLIENT):
        client = testit("Client-" + str(i))
        clientlist.append(client)
        client.start()
    
    for client in clientlist:
        client.join()


    end = time.time()
    util.info("Elapsed time (in seconds): " + str(end-start))

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected");
Esempio n. 6
0
def test(cmd):
    global count
    util.info("")
    util.info("- Starting " + cmd)
    util.info("")
    util.run(cmd)
    
    commands.getoutput("rm -rf " + file1)
    commands.getoutput("rm -rf " + file2)
    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &");
    time.sleep(0.3)
#    os.system("./testclient localhost 2010 /testdata/file-sff-large.txt > /tmp/file1 &");
    os.system("./testclient localhost 2010 /testdata/file-sff-large.txt > %s &" % file1);
#   time.sleep(0.1)
    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &");
#   time.sleep(0.1)
#    os.system("./testclient localhost 2010 /testdata/file-sff-small.txt > /tmp/file2 &");
    os.system("./testclient localhost 2010 /testdata/file-sff-small.txt > %s &" % file2);


    time.sleep(3 *  CGI_SPIN_TIME)
    time.sleep(5) # this doesn't hurt
    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected");

    # time1 = os.path.getmtime(file1)
    # time2 = os.path.getmtime(file2)

    time_decimal1 = str(os.path.getmtime(file1))
    time_decimal2 = str(os.path.getmtime(file2))

   
    # print time_decimal1
    # print time_decimal2

    passed = Decimal(time_decimal1).compare_total(Decimal(time_decimal2)) != -1

    # passed = time1 > time2

    if passed:
        print ""
        print "#####################################"
        print "GOOD! you implement SFF correctly"
        print "#####################################"
        print ""
        count = count + 1
    else:
        print ""
        print "#####################################"
        print "Oh oh! ERROR ERROR!"
        print "SFF is not implemented correctly"
        print "#####################################"
        print ""
        sys.exit(-1)

    util.kill()
Esempio n. 7
0
def test(cmd):
    global count
    util.info("")
    util.info("- Starting " + cmd)
    util.info("")
    util.run(cmd)

    commands.getoutput("rm -rf " + file1)
    commands.getoutput("rm -rf " + file2)
    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &")
    time.sleep(0.3)
    #    os.system("./testclient localhost 2010 /testdata/file-sff-large.txt > /tmp/file1 &");
    os.system(
        "./testclient localhost 2010 /testdata/file-sff-large.txt > %s &" %
        file1)
    #   time.sleep(0.1)
    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &")
    #   time.sleep(0.1)
    #    os.system("./testclient localhost 2010 /testdata/file-sff-small.txt > /tmp/file2 &");
    os.system(
        "./testclient localhost 2010 /testdata/file-sff-small.txt > %s &" %
        file2)

    time.sleep(3 * CGI_SPIN_TIME)
    time.sleep(5)  # this doesn't hurt
    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected")

    time1 = os.path.getmtime(file1)
    time2 = os.path.getmtime(file2)

    print time1
    print time2

    passed = time1 > time2

    if passed:
        print ""
        print "#####################################"
        print "GOOD! you implement SFF correctly"
        print "#####################################"
        print ""
        count = count + 1
    else:
        print ""
        print "#####################################"
        print "Oh oh! ERROR ERROR!"
        print "SFF is not implemented correctly"
        print "#####################################"
        print ""
        sys.exit(-1)

    util.kill()
Esempio n. 8
0
def test(cmd):

    print ""
    print "- Starting " + cmd
    util.run2(cmd)
    
    if util.is_server_alive(cmd) != -1:
        util.error("Ouch! Server is still alive!")

    print ""
    print "GOOD! ..."
    print ""
Esempio n. 9
0
def test(cmd):

    print ""
    print "- Starting " + cmd
    util.run2(cmd)

    if util.is_server_alive(cmd) != -1:
        util.error("Ouch! Server is still alive!")

    print ""
    print "GOOD! ..."
    print ""
Esempio n. 10
0
def test(cmd):
    util.info("")
    util.info("- Starting " + cmd)
    util.info("")
    util.run(cmd)

    start = time.time()

    clientlist = []

    for i in range(0, NUM_CLIENT):
        client = testit("Client-" + str(i))
        clientlist.append(client)
        client.start()

    for client in clientlist:
        client.join()

    end = time.time()
    util.info("Elapsed time (in seconds): " + str(end - start))

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected")
Esempio n. 11
0
def test(cmd):
    global expected
    global got
    global count

    util.info("")
    util.info("- Starting " + cmd)
    util.info("")
    util.run(cmd)

    expected = ['MAGIC:a', 'MAGIC:bb', 'MAGIC:ccc']

    commands.getoutput("rm -rf %s" % tmpfile)
    commands.getoutput("rm -rf " + file1)
    commands.getoutput("rm -rf " + file2)
    commands.getoutput("rm -rf " + file3)

    os.system("./testclient localhost 2010 /output10.cgi >> /dev/null &")
    time.sleep(1)
    #    os.system("./testclient localhost 2010 /testdata/file1.txt > /tmp/file1 &");
    os.system("./testclient localhost 2010 /testdata/file1.txt > %s &" % file1)
    time.sleep(1)
    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &")
    time.sleep(1)
    #    os.system("./testclient localhost 2010 /testdata/file2.txt > /tmp/file2 &");
    os.system("./testclient localhost 2010 /testdata/file2.txt > %s &" % file2)
    time.sleep(1)
    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &")
    time.sleep(1)
    #    os.system("./testclient localhost 2010 /testdata/file3.txt > /tmp/file3 &");
    os.system("./testclient localhost 2010 /testdata/file3.txt > %s &" % file3)

    time.sleep(10 + 2 * CGI_SPIN_TIME + 2)

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected")

    time1 = os.path.getmtime(file1)
    time2 = os.path.getmtime(file2)
    time3 = os.path.getmtime(file3)

    res1 = commands.getoutput("cat " + file1)
    res2 = commands.getoutput("cat " + file2)
    res3 = commands.getoutput("cat " + file3)

    print res1
    print res2
    print res3

    print expected[0]
    pos1 = res1.find(expected[0])
    print expected[1]
    pos2 = res2.find(expected[1])
    print expected[2]
    pos3 = res3.find(expected[2])

    print time1
    print time2
    print time3

    print pos1
    print pos2
    print pos3

    passed = time1 < time2 and time2 < time3
    passed = passed and pos1 > 0 and pos2 > 0 and pos3 > 0

    if passed:
        print ""
        print "#####################################"
        print "GOOD! you passed this iteration"
        print "There may be more..."
        print "#####################################"
        print ""
        count = count + 1
    else:
        print ""
        print "#####################################"
        print "Oh oh! ERROR ERROR!"
        print "FIFO is not implemented correctly"
        print "#####################################"
        print ""
        sys.exit(-1)

    util.kill()
Esempio n. 12
0
def test(cmd):
    global res_list
    print ""
    print "Starting " + cmd
    util.run(cmd)
    
    clientlist = []
    res_list = []

    for i in range(0, NUM_CLIENT):
        client = testit("Client-" + str(i))
        clientlist.append(client)
        client.start()
    
    for client in clientlist:
        client.join()

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected");

    sum = 0; # this sum of the thread id

    for res in res_list:
        print res
        # do sanity check
        lines = res.split("\n")
        thread_info = []
        for line in lines:
            if line.find("Stat-thread") >= 0:
                thread_info.append(line)
        
        
        # check thread id
        header, field, value = thread_info[0].split(":")
        if field.find("Stat-thread-id") < 0: 
            util.error("Uh oh! Stat-thread-id should appear in the order indicated"
                       "in the spec")
        if int(value) > 1 or int(value) < 0:
            util.error("Ouchs! Thread id should be from 0 to N-1 (N is no of threads)")
        sum = sum + int(value)

        # check thread count
        header, field, value = thread_info[1].split(":")
        if field.find("Stat-thread-count") < 0:
            util.error("Ouchs! Stat-thread-count should appear right after Stat-thread-id")
        if int(value) != 1:
            util.error("Ouchs! Stat-thread-count should be 1")
        
        # check thread static
        header, field, value = thread_info[2].split(":")
        if field.find("Stat-thread-static") < 0:
            util.error("Ouchs! Stat-thread-static should appear right after "
                       "Stat-thread-count")
        if int(value) != 0:
            util.error("Ouchs! Stat-thread-static should be 0")

        # check thread dynamic
        header, field, value = thread_info[3].split(":")
        if field.find("Stat-thread-dynamic") < 0:
            util.error("Ouchs! Stat-thread-dynamic should appear right after "
                       "Stat-thread-static")
        if int(value) != 1:
            util.error("Ouchs! Stat-thread-dynamic should be 1")

    if sum != (NUM_CLIENT-1) * NUM_CLIENT / 2:
        util.error("Ouchs! Stat-thread-id is assigned incorrectly")

    
    print ""
    print "GOOD! you passed this test"
    print ""
Esempio n. 13
0
def test(cmd):
    global count
    util.info("")
    util.info("- Starting " + cmd)
    util.info("")
    util.run(cmd)
    
    commands.getoutput("rm -rf " + file1)
    commands.getoutput("rm -rf " + file2)
    commands.getoutput("rm -rf " + file3)
    commands.getoutput("rm -rf " + file4)

    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &");
    time.sleep(0.6)
#    os.system("./testclient localhost 2010 /testdata/file-sff-large.txt > /tmp/file1 &");
    os.system("./testclient localhost 2010 /testdata/file-sff-large.txt > %s &" % file1);
    time.sleep(0.1)
#    os.system("./testclient localhost 2010 /testdata/file-sff-small.txt > /tmp/file2 &");
    os.system("./testclient localhost 2010 /testdata/file-sff-small.txt > %s &" % file2);
    time.sleep(0.1)
    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &");
    time.sleep(0.1)
#    os.system("./testclient localhost 2010 /testdata/file-sff-large.txt > /tmp/file3 &");
    os.system("./testclient localhost 2010 /testdata/file-sff-large.txt > %s &" % file3);
    time.sleep(0.1)
#    os.system("./testclient localhost 2010 /testdata/file-sff-small.txt > /tmp/file4 &");
    os.system("./testclient localhost 2010 /testdata/file-sff-small.txt > %s &" % file4);
    time.sleep(0.1)
    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &");

    time.sleep(4 * CGI_SPIN_TIME + 3)

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected");

    time1 = os.path.getmtime(file1)
    time2 = os.path.getmtime(file2)
    time3 = os.path.getmtime(file3)
    time4 = os.path.getmtime(file4)
  
    print "time1 = " + str(time1)
    print "time2 = " + str(time2)
    print "time3 = " + str(time3)
    print "time4 = " + str(time4)


    print "expected = " + "time1 >= time2 and time3 > time4 and time4 >= time1"
    passed = time1 >= time2 and time3 > time4 and time4 >= time1

    if passed:
        print ""
        print "#####################################"
        print "GOOD! you implement SFF correctly"
        print "#####################################"
        print ""
        count = count + 1
    else:
        print ""
        print "#####################################"
        print "Oh oh! ERROR ERROR!"
        print "SFF is not implemented correctly"
        print "#####################################"
        print ""
        sys.exit(-1)

    util.kill()
Esempio n. 14
0
def test(cmd):
    global expected
    global got
    global count

    util.info("")
    util.info("- Starting " + cmd)
    util.info("")
    util.run(cmd)
    
    expected = ['MAGIC:a', 'MAGIC:bb', 'MAGIC:ccc']

    commands.getoutput("rm -rf %s" % tmpfile)
    commands.getoutput("rm -rf " + file1)
    commands.getoutput("rm -rf " + file2)
    commands.getoutput("rm -rf " + file3)

    os.system("./testclient localhost 2010 /output10.cgi >> /dev/null &");
    time.sleep(1)
#    os.system("./testclient localhost 2010 /testdata/file1.txt > /tmp/file1 &");
    os.system("./testclient localhost 2010 /testdata/file1.txt > %s &" % file1);
    time.sleep(1)
    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &");
    time.sleep(1)
#    os.system("./testclient localhost 2010 /testdata/file2.txt > /tmp/file2 &");
    os.system("./testclient localhost 2010 /testdata/file2.txt > %s &" % file2);
    time.sleep(1)
    os.system("./testclient localhost 2010 /output.cgi >> /dev/null &");
    time.sleep(1)
#    os.system("./testclient localhost 2010 /testdata/file3.txt > /tmp/file3 &");
    os.system("./testclient localhost 2010 /testdata/file3.txt > %s &" % file3);



    time.sleep(10 +  2 * CGI_SPIN_TIME + 2);

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected");

    time1 = os.path.getmtime(file1)
    time2 = os.path.getmtime(file2)
    time3 = os.path.getmtime(file3)
   
    res1 = commands.getoutput("cat " + file1);
    res2 = commands.getoutput("cat " + file2);
    res3 = commands.getoutput("cat " + file3);
    
    print res1
    print res2
    print res3
    
    print expected[0]
    pos1 = res1.find(expected[0])
    print expected[1]
    pos2 = res2.find(expected[1])
    print expected[2]
    pos3 = res3.find(expected[2])

    print time1
    print time2
    print time3

    print pos1
    print pos2
    print pos3

    passed = time1 < time2 and time2 < time3 
    passed = passed and pos1 > 0 and pos2 > 0 and pos3 > 0

    if passed:
        print ""
        print "#####################################"
        print "GOOD! you passed this iteration"
        print "There may be more..."
        print "#####################################"
        print ""
        count = count + 1
    else:
        print ""
        print "#####################################"
        print "Oh oh! ERROR ERROR!"
        print "FIFO is not implemented correctly"
        print "#####################################"
        print ""
        sys.exit(-1)

    util.kill()
Esempio n. 15
0
def test(cmd):
    global expected
    global got
    global count

    util.info("")
    util.info("- Starting " + cmd)
    util.info("")
    util.run(cmd)

    start = time.time()

    clientlist = []
    expected = []
    for i in range(1, NUM_CLIENT):
        expected.append(
            commands.getoutput("cat ./testdata/file%s.txt" % str(i)))

    commands.getoutput("rm -rf %s" % tmpfile)

    for i in range(0, NUM_CLIENT):
        client = testit("Client-" + str(i), i)
        clientlist.append(client)
        client.start()
        time.sleep(0.3)

    for client in clientlist:
        client.join()

    end = time.time()
    util.info("Elapsed time (in seconds): " + str(end - start))

    time.sleep(CGI_SPIN_TIME + 2)
    res = commands.getoutput("cat %s" % tmpfile)

    if util.is_server_alive(cmd) == -1:
        util.error("Ouch! Server is dead!"
                   " Your bounded buffered may not be well protected")

    pos0 = res.find(expected[0])
    pos1 = res.find(expected[1])
    pos2 = res.find(expected[2])
    passed = pos0 > 0 and pos1 > 0 and pos2 > 0 and pos0 < pos1 and pos1 < pos2

    util.info(res)

    if passed:
        print ""
        print "#####################################"
        print "GOOD! you implement SFF correctly"
        print "#####################################"
        print ""
        count = count + 1
    else:
        print ""
        print "#####################################"
        print "Oh oh! ERROR ERROR!"
        print "SFF is not implemented correctly"
        print "#####################################"
        print ""
        sys.exit(-1)