added lwm2m-ipso test

This commit is contained in:
Joakim Eriksson 2017-11-29 22:44:41 +01:00 committed by Niclas Finne
parent c86b763e5d
commit 6c729f50d6
6 changed files with 138 additions and 1 deletions

View File

@ -216,9 +216,11 @@ int
coap_endpoint_is_connected(const coap_endpoint_t *ep)
{
#if UIP_CONF_IPV6_RPL
#ifndef CONTIKI_TARGET_NATIVE
if(rpl_get_any_dag() == NULL) {
return 0;
}
#endif
#endif /* UIP_CONF_IPV6_RPL */
#ifdef WITH_DTLS

View File

@ -72,11 +72,11 @@ static led_state_t leds_controls[LEDS_CONTROL_NUMBER];
static lwm2m_status_t
set_value(ipso_control_t *control, uint8_t value)
{
#if PLATFORM_HAS_LEDS
led_state_t *state;
state = (led_state_t *)control;
#if PLATFORM_HAS_LEDS
if(value) {
leds_on(state->led_value);
} else {

View File

@ -176,9 +176,12 @@ static int
has_network_access(void)
{
#if UIP_CONF_IPV6_RPL
/* NATIVE PLATFORM is not really running RPL */
#ifndef CONTIKI_TARGET_NATIVE
if(rpl_get_any_dag() == NULL) {
return 0;
}
#endif
#endif /* UIP_CONF_IPV6_RPL */
return 1;
}

View File

@ -0,0 +1,60 @@
#!/bin/bash
# Contiki directory
CONTIKI=$1
# Test basename
BASENAME=06-lwm2m-test
IPADDR=fd00::302:304:506:708
echo "Enabling IPv6"
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
# Starting Contiki-NG native node
echo "Starting native node - lwm2m/ipso objects"
make -C $CONTIKI/examples/ipso-objects/example-ipso-objects > make.log 2> make.err
sudo $CONTIKI/examples/ipso-objects/example-ipso-objects.native > node.log 2> node.err &
CPID=$!
sleep 10
echo "Downloading leshan"
wget -nc https://joakimeriksson.github.io/resources/leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar
echo "Starting leshan server"
java -jar leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar >leshan.log 2>leshan.err &
LESHID=$!
sleep 50
echo "Closing native node"
sleep 1
pgrep ipso | sudo xargs kill -9
echo "Closing leshan"
sleep 1
pgrep java | sudo xargs kill -9
if grep -q 'OK' leshan.err ; then
cp leshan.err $BASENAME.testlog;
printf "%-32s TEST OK\n" "$BASENAME" | tee $BASENAME.testlog;
else
echo "==== make.log ====" ; cat make.log;
echo "==== make.err ====" ; cat make.err;
echo "==== node.log ====" ; cat node.log;
echo "==== node.err ====" ; cat node.err;
echo "==== leshan.log ====" ; cat leshan.log;
echo "==== leshan.err ====" ; cat leshan.err;
echo "==== $BASENAME.log ====" ; cat $BASENAME.log;
printf "%-32s TEST FAIL\n" "$BASENAME" | tee $BASENAME.testlog;
fi
rm make.log
rm make.err
rm node.log
rm node.err
rm leshan.log
rm leshan.err
# We do not want Make to stop -> Return 0
# The Makefile will check if a log contains FAIL at the end
exit 0

View File

@ -0,0 +1 @@
include ../Makefile.script-test

View File

@ -0,0 +1,71 @@
import unittest, array, time
class TestDevice(unittest.TestCase):
global client
def test_available_power_sources(self):
r = client.readTLV("3/0/6")
self.assertEqual(r.getCode().getName(), "CONTENT")
def test_device_read_JSON(self):
r = client.readJSON("3/0/1")
self.assertEqual(r.getCode().getName(), "CONTENT")
def test_manufacturer_read(self):
r = client.read("3/0/0")
self.assertEqual(r.getCode().getName(), "CONTENT")
def test_manufacturer_readJSON(self):
r = client.readJSON("3/0/0")
self.assertEqual(r.getCode().getName(), "CONTENT")
def test_manufacturer_write(self):
r = client.write(3, 0, 0, "abc");
self.assertEqual(r.getCode().getName(), "METHOD_NOT_ALLOWED")
def test_manufacturer_execute(self):
r = client.execute("3/0/0")
self.assertEqual(r.getCode().getName(), "METHOD_NOT_ALLOWED")
def test_reboot_read(self):
r = client.read("3/0/4")
self.assertEqual(r.getCode().getName(), "METHOD_NOT_ALLOWED")
# def test_opaque_read(self):
# r = client.readTLV("4711/0/11000")
# v = r.getContent().getValue();
#print "Result:", v
#print "Type: ", type(v)
#print "Type code: ", v.typecode
#print "Data size: ", len(v)
# self.assertEqual(len(v), 900)
# def test_object_with_opaque_read(self):
# r = client.readTLV("4711/0/")
# self.assertEqual(r.getCode().getName(), "CONTENT")
def test_device_time_write(self):
r = client.write(3,0,13,1000)
self.assertEqual(r.getCode().getName(), "CHANGED")
time.sleep(4.9)
r = client.read("3/0/13")
v = r.getContent().getValue().getTime()
self.assertTrue(v > 1000)
print "Time: ", v
print "----------------------------------------"
print "LWM2M Tester - name of client: ", client.endpoint
print "----------------------------------------"
r = client.read("3/0/0");
print "Code:", r.getCode(), r.getCode().getName() == "CONTENT"
print "Objects: ", client.links
print "Read Manufacturer => ", client.read("3/0/0")
print "Read Device => ", client.readTLV("3/0/")
print "Write Manufacturer => ", client.write(3, 0, 0, "abc")
print "Exe Manufacturer => ", client.execute("3/0/0")
suite = unittest.TestLoader().loadTestsFromTestCase(TestDevice)
unittest.TextTestRunner(verbosity=2).run(suite)