def test_room_application_collection(self): ''' When number is 2 and request is put, room entity handler give light and fan response. So, there are 3 responses output: In Server CPP entity handler. In the middle one, it will handle light and fan. @fn test_room_application_collection @param self @return ''' # start server server_cmd = "/opt/iotivity/examples/resource/cpp/roomserver 2 > /tmp/svr_output &" run_as("iotivity-tester", server_cmd) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/roomclient > /tmp/output &" run_as("iotivity-tester", client_cmd) time.sleep(6) (status, output) = run_as("iotivity-tester", "cat /tmp/svr_output") # kill server and client self.target.run("killall roomserver roomclient") time.sleep(3) ## # TESTPOINT: #1, test_room_application_collection # self.assertEqual(output.count("In Server CPP entity handler"), 3, msg="CPP entity handler is: %s" % output)
def test_simple(self): ''' Test simpleserver and simpleclient. After finding resource, simpleclient will do: GET, PUT, POST, Observer sequencely. @fn test_simple @param self @return ''' # start server server_cmd = "/opt/iotivity/examples/resource/cpp/simpleserver > /tmp/svr_output &" (status, output) = run_as("iotivity-tester", server_cmd, timeout=90) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/simpleclient > /tmp/output &" run_as("iotivity-tester", client_cmd, timeout=90) print "\npatient... simpleclient needs long time for its observation" time.sleep(70) (status, output) = run_as("iotivity-tester", 'cat /tmp/output') # judge if the values are correct ret = 0 if "DISCOVERED Resource" in output and \ "GET request was successful" in output and \ "PUT request was successful" in output and \ "POST request was successful" in output and \ "Observe is used." in output: pass else: ret = 1 # kill server and client self.target.run("killall simpleserver simpleclient") time.sleep(3) ## # TESTPOINT: #1, test_simple # self.assertEqual(ret, 0, msg="Error messages: %s" % output)
def test_threadingsample(self): ''' Test threadingsample. In its main(), a foo1 server registered. Then, it opens three threads: 1> second server foo2 2> clinet1 to detect foo1 3> client2 to detect foo2, and does GET/PUT further @fn test_threadingsample @param self @return ''' # start test client_cmd = "/opt/iotivity/examples/resource/cpp/threadingsample > /tmp/output &" run_as("iotivity-tester", client_cmd, timeout=20) print "\n patient, threadingsample needs some time to open 3 threads" time.sleep(20) (status, output) = run_as("iotivity-tester", 'cat /tmp/output') # judge if the values are correct ret = 0 if "URI: /q/foo1" in output and \ "URI: /q/foo2" in output and \ "Successful Get." in output and \ "Successful Put." in output: pass else: ret = 1 # kill test self.target.run("killall threadingsample") time.sleep(3) ## # TESTPOINT: #1, test_threadingsample # self.assertEqual(ret, 0, msg="Error messages: %s" % output)
def test_simpleclientserver(self): ''' Test simpleclientserver. It foos a server, and start client to do GET/PUT. @fn test_simpleclientserver @param self @return ''' # start test client_cmd = "/opt/iotivity/examples/resource/cpp/simpleclientserver > /tmp/output &" run_as("iotivity-tester", client_cmd, timeout=20) time.sleep(10) (status, output) = run_as("iotivity-tester", 'cat /tmp/output') # judge if the values are correct ret = 0 if "Found Resource" in output and \ "Successful Get" in output and \ "Successful Put" in output and \ "barCount: 211" in output: pass else: ret = 1 # kill test self.target.run("killall simpleclientserver") time.sleep(3) ## # TESTPOINT: #1, test_simpleclientserver # self.assertEqual(ret, 0, msg="Error messages: %s" % output)
def test_devicediscovery(self): ''' Test devicediscoveryserver and devicediscoveryclient. The server registers platform info values, the client connects to the server and fetch the information to print out. @fn test_devicediscovery @param self @return ''' # ensure env is clean # start server server_cmd = "/opt/iotivity/examples/resource/cpp/devicediscoveryserver > /tmp/svr_output &" (status, output) = run_as("iotivity-tester", server_cmd, timeout=20) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/devicediscoveryclient > /tmp/output &" run_as("iotivity-tester", client_cmd, timeout=20) time.sleep(5) (status, output) = run_as("iotivity-tester", 'cat /tmp/output') # judge if the values are correct ret = 0 if "Device name" in output and "Bill's Battlestar" in output: pass else: ret = 1 # kill server and client self.target.run("killall devicediscoveryserver devicediscoveryclient") time.sleep(3) ## # TESTPOINT: #1, test_devicediscovery # self.assertEqual(ret, 0, msg="Error messages: %s" % output)
def test_devicediscovery(self): ''' Test devicediscoveryserver and devicediscoveryclient. The server registers platform info values, the client connects to the server and fetch the information to print out. @fn test_devicediscovery @param self @return ''' # ensure env is clean # start server server_cmd = "/opt/iotivity/examples/resource/cpp/devicediscoveryserver > /tmp/svr_output &" (status, output) = run_as("iotivity-tester", server_cmd, timeout=20) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/devicediscoveryclient > /tmp/output &" run_as("iotivity-tester", client_cmd, timeout=20) time.sleep(5) (status, output) = run_as("iotivity-tester", 'cat /tmp/output') # judge if the values are correct ret = 0 if "Device name" in output and "Bill's Battlestar" in output and \ "Spec version url" in output and "core.1.0.0" in output and \ "Data Model Model" in output and "res.1.0.0" in output: pass else: ret = 1 # kill server and client self.target.run("killall devicediscoveryserver devicediscoveryclient") time.sleep(3) ## # TESTPOINT: #1, test_devicediscovery # self.assertEqual(ret, 0, msg="Error messages: %s" % output)
def test_room_default_collection(self): ''' When number is 1 and request is put, light and fan give response individually. So, there is no 'In Server CPP entity handler' output. Each respone is given by light or fan. @fn test_room_default_collection @param self @return ''' # start server server_cmd = "/opt/iotivity/examples/resource/cpp/roomserver 1 > /tmp/svr_output &" (status, output) = run_as("iotivity-tester", server_cmd) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/roomclient > /tmp/output &" run_as("iotivity-tester", client_cmd) time.sleep(5) (status, output) = run_as( "iotivity-tester", "cat /tmp/svr_output | grep 'In Server CPP entity handler' -c") # kill server and client self.target.run("killall roomserver roomclient") time.sleep(3) ## # TESTPOINT: #1, test_room_default_collection # self.assertEqual(int(output), 0, msg="CPP entity handler is: %s" % output)
def test_room_default_collection(self): ''' When number is 1 and request is put, light and fan give response individually. So, there is no 'In Server CPP entity handler' output. Each respone is given by light or fan. @fn test_room_default_collection @param self @return ''' # start server server_cmd = "/opt/iotivity/examples/resource/cpp/roomserver 1 > /tmp/svr_output &" (status, output) = run_as("iotivity-tester", server_cmd) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/roomclient > /tmp/output &" run_as("iotivity-tester", client_cmd) time.sleep(5) (status, output) = run_as("iotivity-tester", "cat /tmp/svr_output | grep 'In Server CPP entity handler' -c") # kill server and client self.target.run("killall roomserver roomclient") time.sleep(3) ## # TESTPOINT: #1, test_room_default_collection # self.assertEqual(string.atoi(output), 0, msg="CPP entity handler is: %s" % output)
def setUpClass(cls): '''Test simpleserver and simpleclient. @fn setUpClass @param cls @return ''' cls.tc.target.run("killall simpleserver") cls.tc.target.run("killall simpleclient") # add group and non-root user add_group("tester") add_user("iotivity-tester", "tester") # start server server_cmd = "/opt/iotivity/examples/resource/cpp/simpleserver > /tmp/svr_output &" run_as("iotivity-tester", server_cmd) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/simpleclient > /tmp/output &" run_as("iotivity-tester", client_cmd) print "\npatient... simpleclient needs long time for its observation" time.sleep(60) # If there is no 'Observe is used', give a retry. (status, output) = cls.tc.target.run('cat /tmp/output') if "Observe is used." in output: pass else: cls.tc.target.run("killall simpleserver") cls.tc.target.run("killall simpleclient") time.sleep(2) (status, output) = cls.tc.target.run(server_cmd) cls.tc.target.run(client_cmd) time.sleep(60)
def test_threadingsample(self): ''' Test threadingsample. In its main(), a foo1 server registered. Then, it opens three threads: 1> second server foo2 2> clinet1 to detect foo1 3> client2 to detect foo2, and does GET/PUT further @fn test_threadingsample @param self @return ''' # start test client_cmd = "/opt/iotivity/examples/resource/cpp/threadingsample > /tmp/output &" run_as("iotivity-tester", client_cmd, timeout=20) print("\n patient, threadingsample needs some time to open 3 threads") time.sleep(20) (status, output) = run_as("iotivity-tester", 'cat /tmp/output') # judge if the values are correct ret = 0 if "URI: /q/foo1" in output and \ "URI: /q/foo2" in output and \ "Successful Get." in output and \ "Successful Put." in output: pass else: ret = 1 # kill test self.target.run("killall threadingsample") time.sleep(3) ## # TESTPOINT: #1, test_threadingsample # self.assertEqual(ret, 0, msg="Error messages: %s" % output)
def test_mnode_group(self): ''' groupclient has 4 main operations. Only option1 is doable. In option (user inputs 1), it will set ActionSet value of rep. This case is to check if the set operation is done. @fn test_group @param self @return ''' # start light server and group server lightserver_cmd = "/opt/iotivity/examples/resource/cpp/lightserver > /tmp/svr_output &" (status, output) = run_as("root", lightserver_cmd, target=self.targets[1]) time.sleep(2) ssh_cmd = "ssh root@%s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR" % self.targets[1].ip groupserver_cmd = "/opt/iotivity/examples/resource/cpp/groupserver > /dev/null 2>&1" subprocess.Popen("%s %s" % (ssh_cmd, groupserver_cmd), shell=True) time.sleep(3) # start client to get info, here needs user input. So use expect exp_cmd = os.path.join(os.path.dirname(__file__), "files/group_client.exp") status, output = shell_cmd_timeout("expect %s %s" % (exp_cmd, self.target.ip), timeout=200) # kill server and client run_as("root", "killall lightserver groupserver groupclient", target=self.targets[0]) run_as("root", "killall lightserver groupserver groupclient", target=self.targets[1]) time.sleep(3) ## # TESTPOINT: #1, test_group # if type(output) is bytes: output = output.decode('ascii') self.assertEqual(status, 2, msg="expect excution fail\n %s" % output)
def test_garage(self): ''' Test garageserver and garageclient. While server and client communication, remove one attribute Name from OCRepresentation. Then the attribute number of OCRepresentation should reduce 1. @fn test_garage @param self @return ''' # start server server_cmd = "/opt/iotivity/examples/resource/cpp/garageserver > /tmp/svr_output &" (status, output) = run_as("iotivity-tester", server_cmd, timeout=20) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/garageclient > /tmp/output &" run_as("iotivity-tester", client_cmd, timeout=20) time.sleep(5) (status, output) = run_as("iotivity-tester", 'cat /tmp/output') # judge if the values are correct ret = 0 if "GET request was successful" in output and \ "attribute: name, was removed successfully from rep2." in output and \ "Number of attributes in rep2: 6" in output and \ "PUT request was successful" in output: pass else: ret = 1 # kill server and client self.target.run("killall garageserver garageclient") time.sleep(3) ## # TESTPOINT: #1, test_garage # self.assertEqual(ret, 0, msg="Error messages: %s" % output)
def get_server_ipv6(self): """ @fn get_server_ipv6 @param self @return """ time.sleep(1) # Check ip address by ifconfig command interface = "nothing" (status, interface) = run_as("root", "ifconfig | grep '^enp'", target=self.targets[1]) (status, output) = run_as("root", "ifconfig %s | grep 'inet6 addr:'" % interface.split()[0], target=self.targets[1]) return output.split('%')[0].split()[-1]
def presence_check(self, para): '''this is a function used by presence test @fn presence_check @param self @return ''' # start server server_cmd = "/opt/iotivity/examples/resource/cpp/presenceserver > /tmp/svr_output &" (status, output) = run_as("iotivity-tester", server_cmd, target=self.targets[1]) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/presenceclient -t %d > /tmp/output &" % para run_as("iotivity-tester", client_cmd, target=self.targets[0]) # Some platform is too slow, it needs more time to sleep. E.g. MinnowMax time.sleep(60) (status, output) = run_as("iotivity-tester", "cat /tmp/output", target=self.targets[0]) run_as("root", "killall presenceserver presenceclient", target=self.targets[0]) run_as("root", "killall presenceserver presenceclient", target=self.targets[1]) time.sleep(3) return output.count("Received presence notification from : %s" % self.targets[1].ip) + \ output.count("Received presence notification from : %s" % self.get_server_ipv6())
def test_mnode_fridge(self): ''' Test fridgeserver and fridgeclient. The server registers resource with 2 doors and 1 light, client connects to the server and fetch the information to print out. @fn test_fridge @param self @return ''' # ensure env is clean # start server server_cmd = "/opt/iotivity/examples/resource/cpp/fridgeserver > /tmp/svr_output &" (status, output) = run_as("iotivity-tester", server_cmd, target=self.targets[1]) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/fridgeclient > /tmp/output &" run_as("iotivity-tester", client_cmd, target=self.targets[0]) time.sleep(5) (status, output) = run_as("iotivity-tester", 'cat /tmp/output', target=self.targets[0]) # judge if the values are correct ret = 0 if "Name of device: Intel Powered 2 door, 1 light refrigerator" in output and \ "Delete ID is 0 and resource URI is /device" in output: pass else: ret = 1 # kill server and client run_as("root", "killall fridgeserver fridgeclient", target=self.targets[0]) run_as("root", "killall fridgeserver fridgeclient", target=self.targets[1]) time.sleep(3) ## # TESTPOINT: #1, test_fridge # self.assertEqual(ret, 0, msg="Error messages: %s" % output)
def tearDownClass(cls): '''disable wifi, it will block ethernet connection when rebooting @fn tearDownClass @param cls @return ''' client_wifi = wifi.WiFiFunction(cls.tc.targets[0]) server_wifi = wifi.WiFiFunction(cls.tc.targets[1]) client_wifi.disable_wifi() server_wifi.disable_wifi() run_as("root", "killall simpleserver simpleclient", target=cls.tc.targets[0]) time.sleep(1) run_as("root", "killall simpleserver simpleclient", target=cls.tc.targets[1]) time.sleep(1)
def get_lowpan0_ip(self, target_number): ''' Get lowpan0 (ipv6) address @fn get_lowpan0_ip @param self @param target_number: 0 stands for main_target, 1 stands for second target @return ''' cmd="ifconfig lowpan0 | grep 'inet6 addr:'" (status, output) = run_as('root', cmd, target=self.targets[target_number]) return output.split('%')[0].split()[2]
def test_mnode_simpleHQ(self): ''' Test simpleserverHQ and simpleclientHQ. Compared to simpleserver, simpleserverHQ removes SlowResponse, and give sendResponse (when PUT) / sendPostResponse (when POST). Basically, they are the same. @fn test_simpleHQ @param self @return ''' for i in range(3): # start server server_cmd = "/opt/iotivity/examples/resource/cpp/simpleserverHQ > /tmp/svr_output &" run_as("iotivity-tester", server_cmd, target=self.targets[1]) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/simpleclientHQ > /tmp/output &" run_as("iotivity-tester", client_cmd, target=self.targets[0]) print( "\npatient... simpleclientHQ needs long time for its observation" ) time.sleep(70) (status, output) = run_as("iotivity-tester", 'cat /tmp/output', target=self.targets[0]) # kill server and client run_as("root", "killall simpleserverHQ simpleclientHQ", target=self.targets[0]) run_as("root", "killall simpleserverHQ simpleclientHQ", target=self.targets[1]) time.sleep(3) # judge if the values are correct ret = 0 if "DISCOVERED Resource" in output and \ "GET request was successful" in output and \ "PUT request was successful" in output and \ "POST request was successful" in output and \ "Observe is used." in output: break else: ret = 1 ## # TESTPOINT: #1, test_simpleHQ # self.assertEqual(ret, 0, msg="Error messages: %s" % output)
def lowpan0_ping6_check(self, main, second): ''' On main target, run ping6 to ping second's ipv6 address @fn ping6_check @param self @param main: main target number @param second: second target number @return ''' cmd='ping6 -I lowpan0 -c 1 %s' % self.get_lowpan0_ip(second) (status, output) = run_as('root', cmd, target=self.targets[main]) assert status == 0, "Ping second target lowpan0 ipv6 address fail: %s" % output
def presence_check(self, para): '''this is a function used by presence test @fn presence_check @param self @return ''' # start server server_cmd = "/opt/iotivity/examples/resource/cpp/presenceserver > /tmp/svr_output &" (status, output) = run_as("iotivity-tester", server_cmd) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/presenceclient -t %d > /tmp/output &" % para run_as("iotivity-tester", client_cmd) # Some platform is too slow, it needs more time to sleep. E.g. MinnowMax time.sleep(60) (status, output) = run_as("iotivity-tester", "cat /tmp/output") self.target.run("killall presenceserver presenceclient") time.sleep(3) return output.count("Received presence notification from : %s" % self.target.ip) + \ output.count("Received presence notification from : %s" % self.get_ipv6())
def setUpClass(cls): # Kill simpleserver and simpleclient cls.tc.target.run("killall simpleserver simpleclient") # Create test user add_group("tester") add_user("iotivity-tester", "tester") # Set up firewall port_range_cmd = "cat /proc/sys/net/ipv4/ip_local_port_range" (status, output) = cls.tc.target.run(port_range_cmd) port_range = "%s:%s" % tuple(output.split()) iptables_cmd = "/usr/sbin/ip6tables -w -A INPUT -s fe80::/10 \ -p udp -m udp --dport %s -j ACCEPT" cls.tc.target.run(iptables_cmd % "5683") cls.tc.target.run(iptables_cmd % "5684") cls.tc.target.run(iptables_cmd % port_range) # Start server resource_cmd = "/opt/iotivity/examples/resource/cpp/%s > /tmp/%s &" run_as("iotivity-tester", resource_cmd % ("simpleserver", "svr_output")) time.sleep(1) # Start client to get info run_as("iotivity-tester", resource_cmd % ("simpleclient", "output")) print("\npatient... simpleclient needs long time for its observation") time.sleep(10) # If there is no 'Observe is used', give a retry. (status, __) = cls.tc.target.run('grep "Observe is used." /tmp/output') if status != 0: cls.tc.target.run("killall simpleserver simpleclient") time.sleep(2) cls.tc.target.run(resource_cmd % ("simpleserver", "svr_output")) cls.tc.target.run(resource_cmd % ("simpleclient", "output")) time.sleep(10)
def atmel_enable_lowpan0(self, target_number): ''' enable atmel chipset on target @fn atmel_enable_lowpan0 @param self @param target_number: 0 stands for main_target, 1 stands for second target @return ''' # get device ip for debug my_ip=self.targets[target_number].ip # insert module cmd='modprobe %s' % self.atmel_mod_name (status, output) = run_as('root', cmd, target=self.targets[target_number]) time.sleep(1) assert status == 0, "[%s] Insert atmel module fails: %s" % (my_ip, output) # set wpan0 ip_set="ip link set wpan0 address a0:0:0:0:0:0:0:%d" % (target_number+1) (status, output) = run_as('root', ip_set, target=self.targets[target_number]) time.sleep(1) # set channel as 5 wpan_set="iz set wpan0 777 800%d 5" % (target_number+1) (status, output) = run_as('root', wpan_set, target=self.targets[target_number]) time.sleep(1) # bring up wpan0 (status, output) = run_as('root', 'ifconfig wpan0 up', target=self.targets[target_number]) time.sleep(1) assert status == 0, "[%s] Bring up wpan0 fails: %s" % (my_ip, output) # add lowpan0 (status, output) = run_as('root', 'ip link add link wpan0 name lowpan0 type lowpan', target=self.targets[target_number]) time.sleep(1) # bring up lowpan0 (status, output) = run_as('root', 'ifconfig lowpan0 up', target=self.targets[target_number]) time.sleep(1) assert status == 0, "[%s] Bring up lowpan0 fails: %s" % (my_ip, output)
def setUpClass(cls): '''Test simpleserver and simpleclient. @fn setUpClass @param cls @return ''' cls.tc.target.run("killall simpleserver") cls.tc.target.run("killall simpleclient") # add group and non-root user add_group("tester") add_user("iotivity-tester", "tester") # set up firewall (status, output) = cls.tc.target.run("cat /proc/sys/net/ipv4/ip_local_port_range") port_range = output.split() cls.tc.target.run("/usr/sbin/ip6tables -w -A INPUT -s fe80::/10 -p udp -m udp --dport 5683 -j ACCEPT") cls.tc.target.run("/usr/sbin/ip6tables -w -A INPUT -s fe80::/10 -p udp -m udp --dport 5684 -j ACCEPT") cls.tc.target.run("/usr/sbin/ip6tables -w -A INPUT -s fe80::/10 -p udp -m udp --dport %s:%s -j ACCEPT" % (port_range[0], port_range[1])) # start server server_cmd = "/opt/iotivity/examples/resource/cpp/simpleserver > /tmp/svr_output &" run_as("iotivity-tester", server_cmd) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/simpleclient > /tmp/output &" run_as("iotivity-tester", client_cmd) print ("\npatient... simpleclient needs long time for its observation") time.sleep(60) # If there is no 'Observe is used', give a retry. (status, output) = cls.tc.target.run('cat /tmp/output') if "Observe is used." in output: pass else: cls.tc.target.run("killall simpleserver") cls.tc.target.run("killall simpleclient") time.sleep(2) (status, output) = cls.tc.target.run(server_cmd) cls.tc.target.run(client_cmd) time.sleep(60)
def setUpClass(cls): '''Test simpleserver and simpleclient. @fn setUpClass @param cls @return ''' cls.tc.target.run("killall simpleserver") cls.tc.target.run("killall simpleclient") # add group and non-root user add_group("tester") add_user("iotivity-tester", "tester") # set up firewall (status, output) = cls.tc.target.run("cat /proc/sys/net/ipv4/ip_local_port_range") port_range = output.split() cls.tc.target.run("/usr/sbin/ip6tables -w -A INPUT -s fe80::/10 -p udp -m udp --dport 5683 -j ACCEPT") cls.tc.target.run("/usr/sbin/ip6tables -w -A INPUT -s fe80::/10 -p udp -m udp --dport 5684 -j ACCEPT") cls.tc.target.run("/usr/sbin/ip6tables -w -A INPUT -s fe80::/10 -p udp -m udp --dport %s:%s -j ACCEPT" % (port_range[0], port_range[1])) # start server server_cmd = "/opt/iotivity/examples/resource/cpp/simpleserver > /tmp/svr_output &" run_as("iotivity-tester", server_cmd) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/simpleclient > /tmp/output &" run_as("iotivity-tester", client_cmd) print ("\npatient... simpleclient needs long time for its observation") time.sleep(10) # If there is no 'Observe is used', give a retry. (status, output) = cls.tc.target.run('cat /tmp/output') if "Observe is used." in output: pass else: cls.tc.target.run("killall simpleserver") cls.tc.target.run("killall simpleclient") time.sleep(2) (status, output) = cls.tc.target.run(server_cmd) cls.tc.target.run(client_cmd) time.sleep(10)
def setUpClass(cls): # Kill simpleserver and simpleclient cls.tc.target.run("killall simpleserver simpleclient") # Create test user add_group("tester") add_user("iotivity-tester", "tester") # Set up firewall port_range_cmd = "cat /proc/sys/net/ipv4/ip_local_port_range" (status, output) = cls.tc.target.run(port_range_cmd) port_range = output.split() cls.tc.target.run( "/usr/sbin/nft add chain inet filter iotivity { type filter hook input priority 0\; }" ) cls.tc.target.run( "/usr/sbin/nft add rule inet filter iotivity ip6 saddr fe80::/10 udp dport {5683, 5684, %s-%s} mark set 1" % (port_range[0], port_range[1])) # Start server resource_cmd = "/opt/iotivity/examples/resource/cpp/%s > /tmp/%s &" run_as("iotivity-tester", resource_cmd % ("simpleserver", "svr_output")) time.sleep(1) # Start client to get info run_as("iotivity-tester", resource_cmd % ("simpleclient", "output")) print("\npatient... simpleclient needs long time for its observation") time.sleep(10) # If there is no 'Observe is used', give a retry. (status, __) = cls.tc.target.run('grep "Observe is used." /tmp/output') if status != 0: cls.tc.target.run("killall simpleserver simpleclient") time.sleep(2) cls.tc.target.run(resource_cmd % ("simpleserver", "svr_output")) cls.tc.target.run(resource_cmd % ("simpleclient", "output")) time.sleep(10)
def test_simpleHQ(self): ''' Test simpleserverHQ and simpleclientHQ. Compared to simpleserver, simpleserverHQ removes SlowResponse, and give sendResponse (when PUT) / sendPostResponse (when POST). Basically, they are the same. @fn test_simpleHQ @param self @return ''' for i in range(3): # start server server_cmd = "/opt/iotivity/examples/resource/cpp/simpleserverHQ > /tmp/svr_output &" (status, output) = run_as("iotivity-tester", server_cmd, timeout=90) time.sleep(1) # start client to get info client_cmd = "/opt/iotivity/examples/resource/cpp/simpleclientHQ > /tmp/output &" run_as("iotivity-tester", client_cmd, timeout=90) print "\npatient... simpleclientHQ needs long time for its observation" time.sleep(70) (status, output) = run_as("iotivity-tester", 'cat /tmp/output') # kill server and client self.target.run("killall simpleserverHQ simpleclientHQ") time.sleep(3) # judge if the values are correct ret = 0 if "DISCOVERED Resource" in output and \ "GET request was successful" in output and \ "PUT request was successful" in output and \ "POST request was successful" in output and \ "Observe is used." in output: break else: ret = 1 ## # TESTPOINT: #1, test_simpleHQ # self.assertEqual(ret, 0, msg="Error messages: %s" % output)
def setUpClass(cls): '''Clean all the server and client firstly @fn setUpClass @param cls @return ''' # Init main target run_as("root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[0]) run_as("root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[0]) run_as("root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[0]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[0]) # Init second target run_as("root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[1]) run_as("root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[1]) run_as("root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[1]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[1]) # Clean output file on two targets, main is client part and second is server part run_as("root", "rm -f /tmp/svr_output", target=cls.tc.targets[1]) run_as("root", "rm -f /tmp/output", target=cls.tc.targets[0]) # add group and non-root user on both sides add_group("tester", target=cls.tc.targets[0]) add_user("iotivity-tester", "tester", target=cls.tc.targets[0]) add_group("tester", target=cls.tc.targets[1]) add_user("iotivity-tester", "tester", target=cls.tc.targets[1]) # Setup firewall accept for multicast, on both sides run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5683 -j ACCEPT", target=cls.tc.targets[0]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5684 -j ACCEPT", target=cls.tc.targets[0]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5683 -j ACCEPT", target=cls.tc.targets[1]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5684 -j ACCEPT", target=cls.tc.targets[1])
def setUpClass(cls): '''Clean all the server and client firstly @fn setUpClass @param cls @return ''' # Init main target run_as("root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[0]) run_as("root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[0]) run_as("root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[0]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[0]) # Init second target run_as("root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[1]) run_as("root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[1]) run_as("root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[1]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[1]) # Clean output file on two targets, main is client part and second is server part run_as("root", "rm -f /tmp/svr_output", target=cls.tc.targets[1]) run_as("root", "rm -f /tmp/output", target=cls.tc.targets[0]) # add group and non-root user on both sides add_group("tester", target=cls.tc.targets[0]) add_user("iotivity-tester", "tester", target=cls.tc.targets[0]) add_group("tester", target=cls.tc.targets[1]) add_user("iotivity-tester", "tester", target=cls.tc.targets[1]) # Setup firewall accept for multicast, on both sides run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5683 -j ACCEPT", target=cls.tc.targets[0]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5684 -j ACCEPT", target=cls.tc.targets[0]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5683 -j ACCEPT", target=cls.tc.targets[1]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5684 -j ACCEPT", target=cls.tc.targets[1]) # check if image contains iotivity example applications (status, output) = run_as("root", "ls /opt/iotivity/examples/resource/", target=cls.tc.targets[0]) if "cpp" in output: pass else: assert 1 == 0, 'There is no iotivity exmaple app installed in target0' (status, output) = run_as("root", "ls /opt/iotivity/examples/resource/", target=cls.tc.targets[1]) if "cpp" in output: pass else: assert 1 == 0, 'There is no iotivity exmaple app installed in target1'
def setUpClass(cls): '''Connect to WiFi AP, which contains simpleserver running on it @fn setUpClass @param cls @return ''' client_wifi = wifi.WiFiFunction(cls.tc.targets[0]) server_wifi = wifi.WiFiFunction(cls.tc.targets[1]) ap_type = ssid_config.get("Connect", "type") ssid = ssid_config.get("Connect", "ssid") pwd = ssid_config.get("Connect", "passwd") # Connect wifi of two devices client_wifi.execute_connection(ap_type, ssid, pwd) server_wifi.execute_connection(ap_type, ssid, pwd) # Init main target run_as( "root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[0]) run_as( "root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[0]) run_as( "root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[0]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[0]) # Init second target run_as( "root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[1]) run_as( "root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[1]) run_as( "root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[1]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[1]) # Clean output file on two targets, main is client part and second is server part run_as("root", "rm -f /tmp/svr_output", target=cls.tc.targets[1]) run_as("root", "rm -f /tmp/output", target=cls.tc.targets[0]) # add group and non-root user on both sides add_group("tester", target=cls.tc.targets[0]) add_user("iotivity-tester", "tester", target=cls.tc.targets[0]) add_group("tester", target=cls.tc.targets[1]) add_user("iotivity-tester", "tester", target=cls.tc.targets[1]) # Setup firewall accept for multicast, on both sides run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5683 -j ACCEPT", target=cls.tc.targets[0]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5684 -j ACCEPT", target=cls.tc.targets[0]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5683 -j ACCEPT", target=cls.tc.targets[1]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5684 -j ACCEPT", target=cls.tc.targets[1]) # check if image contains iotivity example applications (status, output) = run_as("root", "ls /opt/iotivity/examples/resource/", target=cls.tc.targets[0]) if "cpp" in output: pass else: assert 1 == 0, 'There is no iotivity exmaple app installed in target0' (status, output) = run_as("root", "ls /opt/iotivity/examples/resource/", target=cls.tc.targets[1]) if "cpp" in output: pass else: assert 1 == 0, 'There is no iotivity exmaple app installed in target1' for i in range(3): # Do simpleclient test server_cmd = "/opt/iotivity/examples/resource/cpp/simpleserver > /tmp/srv_output &" run_as("iotivity-tester", server_cmd, target=cls.tc.targets[1]) client_cmd = "/opt/iotivity/examples/resource/cpp/simpleclient > /tmp/output &" run_as("iotivity-tester", client_cmd, target=cls.tc.targets[0]) print( "\npatient... simpleclient needs long time for its observation" ) time.sleep(70) (status, output) = run_as("iotivity-tester", 'cat /tmp/output', target=cls.tc.targets[0]) if "Observe is used." in output: break # if not pass, will retry. Clean the app run_as("root", "killall simpleserver simpleclient", target=cls.tc.targets[0]) time.sleep(1) run_as("root", "killall simpleserver simpleclient", target=cls.tc.targets[1]) time.sleep(1)
def setUpClass(cls): '''Clean all the server and client firstly @fn setUpClass @param cls @return ''' # Init main target run_as( "root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[0]) run_as( "root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[0]) run_as( "root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[0]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[0]) # Init second target run_as( "root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[1]) run_as( "root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[1]) run_as( "root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[1]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[1]) # Clean output file on two targets, main is client part and second is server part run_as("root", "rm -f /tmp/svr_output", target=cls.tc.targets[1]) run_as("root", "rm -f /tmp/output", target=cls.tc.targets[0]) # add group and non-root user on both sides add_group("tester", target=cls.tc.targets[0]) add_user("iotivity-tester", "tester", target=cls.tc.targets[0]) add_group("tester", target=cls.tc.targets[1]) add_user("iotivity-tester", "tester", target=cls.tc.targets[1]) # Setup firewall accept for multicast, on both sides run_as( "root", "/usr/sbin/nft add rule inet filter input udp dport {5683, 5684} accept", target=cls.tc.targets[0]) run_as( "root", "/usr/sbin/nft add rule inet filter input udp dport {5683, 5684} accept", target=cls.tc.targets[1]) # check if image contains iotivity example applications (status, output) = run_as("root", "ls /opt/iotivity/examples/resource/", target=cls.tc.targets[0]) if "cpp" in output: pass else: assert 1 == 0, 'There is no iotivity exmaple app installed in target0' (status, output) = run_as("root", "ls /opt/iotivity/examples/resource/", target=cls.tc.targets[1]) if "cpp" in output: pass else: assert 1 == 0, 'There is no iotivity exmaple app installed in target1'
def setUpClass(cls): '''Connect to WiFi AP, which contains simpleserver running on it @fn setUpClass @param cls @return ''' client_wifi = wifi.WiFiFunction(cls.tc.targets[0]) server_wifi = wifi.WiFiFunction(cls.tc.targets[1]) ap_type = ssid_config.get("Connect","type") ssid = ssid_config.get("Connect","ssid") pwd = ssid_config.get("Connect","passwd") # Connect wifi of two devices client_wifi.execute_connection(ap_type, ssid, pwd) server_wifi.execute_connection(ap_type, ssid, pwd) # Init main target run_as("root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[0]) run_as("root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[0]) run_as("root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[0]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[0]) # Init second target run_as("root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[1]) run_as("root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[1]) run_as("root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[1]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[1]) # Clean output file on two targets, main is client part and second is server part run_as("root", "rm -f /tmp/svr_output", target=cls.tc.targets[1]) run_as("root", "rm -f /tmp/output", target=cls.tc.targets[0]) # add group and non-root user on both sides add_group("tester", target=cls.tc.targets[0]) add_user("iotivity-tester", "tester", target=cls.tc.targets[0]) add_group("tester", target=cls.tc.targets[1]) add_user("iotivity-tester", "tester", target=cls.tc.targets[1]) # Setup firewall accept for multicast, on both sides run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5683 -j ACCEPT", target=cls.tc.targets[0]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5684 -j ACCEPT", target=cls.tc.targets[0]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5683 -j ACCEPT", target=cls.tc.targets[1]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5684 -j ACCEPT", target=cls.tc.targets[1]) # check if image contains iotivity example applications (status, output) = run_as("root", "ls /opt/iotivity/examples/resource/", target=cls.tc.targets[0]) if "cpp" in output: pass else: assert 1 == 0, 'There is no iotivity exmaple app installed in target0' (status, output) = run_as("root", "ls /opt/iotivity/examples/resource/", target=cls.tc.targets[1]) if "cpp" in output: pass else: assert 1 == 0, 'There is no iotivity exmaple app installed in target1' for i in range(3): # Do simpleclient test server_cmd = "/opt/iotivity/examples/resource/cpp/simpleserver > /tmp/srv_output &" run_as("iotivity-tester", server_cmd, target=cls.tc.targets[1]) client_cmd = "/opt/iotivity/examples/resource/cpp/simpleclient > /tmp/output &" run_as("iotivity-tester", client_cmd, target=cls.tc.targets[0]) print "\npatient... simpleclient needs long time for its observation" time.sleep(70) (status, output) = run_as("iotivity-tester", 'cat /tmp/output', target=cls.tc.targets[0]) if "Observe is used." in output: break # if not pass, will retry. Clean the app run_as("root", "killall simpleserver simpleclient", target=cls.tc.targets[0]) time.sleep(1) run_as("root", "killall simpleserver simpleclient", target=cls.tc.targets[1]) time.sleep(1)
def setUpClass(cls): '''Clean all the server and client firstly @fn setUpClass @param cls @return ''' # Init main target run_as( "root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[0]) run_as( "root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[0]) run_as( "root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[0]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[0]) # Init second target run_as( "root", "killall presenceserver presenceclient devicediscoveryserver devicediscoveryclient", target=cls.tc.targets[1]) run_as( "root", "killall fridgeserver fridgeclient garageserver garageclient groupserver groupclient", target=cls.tc.targets[1]) run_as( "root", "killall roomserver roomclient simpleserver simpleclient simpleserverHQ simpleclientHQ", target=cls.tc.targets[1]) run_as("root", "killall simpleclientserver threadingsample", target=cls.tc.targets[1]) # Clean output file on two targets, main is client part and second is server part run_as("root", "rm -f /tmp/svr_output", target=cls.tc.targets[1]) run_as("root", "rm -f /tmp/output", target=cls.tc.targets[0]) # add group and non-root user on both sides add_group("tester", target=cls.tc.targets[0]) add_user("iotivity-tester", "tester", target=cls.tc.targets[0]) add_group("tester", target=cls.tc.targets[1]) add_user("iotivity-tester", "tester", target=cls.tc.targets[1]) # Setup firewall accept for multicast, on both sides run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5683 -j ACCEPT", target=cls.tc.targets[0]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5684 -j ACCEPT", target=cls.tc.targets[0]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5683 -j ACCEPT", target=cls.tc.targets[1]) run_as("root", "/usr/sbin/iptables -w -A INPUT -p udp --dport 5684 -j ACCEPT", target=cls.tc.targets[1])