summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKari Oikarinen <kari.oikarinen@qt.io>2017-03-02 12:34:52 +0200
committerKari Oikarinen <kari.oikarinen@qt.io>2017-05-02 11:47:27 +0000
commitd96efc1a528f38c1da6830eadd9d096a49495d08 (patch)
tree387c352de97ebba767edd926559ec78e713d1355 /tests
parente1e7ff8f1fd0558559321066cedd62e729621175 (diff)
Configure DHCP server on device before handshake
Change the procedure for a newly detected device: First configure the network and then do the handshake for the device information. The configuring the network part is new and incorporates a new service NetworkConfigurationService. On the device it relies on a script b2qt-gadget-network.sh (or as specified in a command line parameter) which does the actual configuring of the USB network interface. The network configuration to apply is selected from a list of hardcoded candidates from the private use IPv4 ranges available. They are checked against the existing networks on the host and an unused one is picked. On the device the USB interface is configured to use this network and to act as a DHCP server for it. Host will then pick up an IP from this DHCP server automatically. Previous configuration of the host network is thus not necessary and is removed. Task-number: QTBUG-58614 Change-Id: I6a4ed34ef7d5cba9e55e6fa4f07725bb3c00d795 Reviewed-by: Samuli Piippo <samuli.piippo@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/tests.pro1
-rw-r--r--tests/tst_subnet.cpp100
-rw-r--r--tests/tst_subnet.pro20
3 files changed, 121 insertions, 0 deletions
diff --git a/tests/tests.pro b/tests/tests.pro
index cbd10df..7de79f3 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -4,6 +4,7 @@ CONFIG += ordered
SUBDIRS = \
tst_qdbmessage.pro \
tst_stream.pro \
+ tst_subnet.pro \
config_libusb10 {
SUBDIRS += \
diff --git a/tests/tst_subnet.cpp b/tests/tst_subnet.cpp
new file mode 100644
index 0000000..5aa36cf
--- /dev/null
+++ b/tests/tst_subnet.cpp
@@ -0,0 +1,100 @@
+/******************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Debug Bridge.
+**
+** $QT_BEGIN_LICENSE:COMM$
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** $QT_END_LICENSE$
+**
+******************************************************************************/
+#include "../qdb/server/subnet.h"
+
+#include <QtCore/qstring.h>
+#include <QtTest>
+
+using Subnets = std::vector<Subnet>;
+
+bool operator==(const Subnet &lhs, const Subnet &rhs)
+{
+ return lhs.address == rhs.address
+ && lhs.prefixLength == rhs.prefixLength;
+}
+
+class tst_Subnet : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void freeSubnets();
+ void freeSubnets_data();
+ void usedSubnets();
+ void usedSubnets_data();
+};
+
+void tst_Subnet::freeSubnets()
+{
+ QFETCH(Subnets, candidates);
+ QFETCH(Subnets, useds);
+
+ const std::pair<Subnet, bool> result = findUnusedSubnet(candidates, useds);
+ QCOMPARE(result.second, true);
+ QCOMPARE(result.first, candidates[0]);
+}
+
+void tst_Subnet::freeSubnets_data()
+{
+ QTest::addColumn<Subnets>("candidates");
+ QTest::addColumn<Subnets>("useds");
+
+ Subnets candidates = {{QHostAddress{"172.31.0.1"}, 30}};
+ Subnets subnets = {{QHostAddress{"10.9.7.70"}, 22}};
+ QTest::newRow("1") << candidates << subnets;
+ subnets = {{QHostAddress{"10.9.7.70"}, 22},
+ {QHostAddress{"10.30.7.0"}, 22}};
+ QTest::newRow("2") << candidates << subnets;
+ candidates = {{QHostAddress{"10.9.7.254"}, 22}};
+ subnets = {{QHostAddress{"10.9.8.1"}, 22}};
+ QTest::newRow("3") << candidates << subnets;
+}
+
+void tst_Subnet::usedSubnets()
+{
+ QFETCH(Subnets, candidates);
+ QFETCH(Subnets, useds);
+
+ const std::pair<Subnet, bool> result = findUnusedSubnet(candidates, useds);
+ QCOMPARE(result.second, false);
+}
+
+void tst_Subnet::usedSubnets_data()
+{
+ QTest::addColumn<Subnets>("candidates");
+ QTest::addColumn<Subnets>("useds");
+
+ Subnets candidates = {{QHostAddress{"10.9.7.0"}, 30}};
+ Subnets subnets = {{QHostAddress{"10.9.4.70"}, 22}};
+ QTest::newRow("1") << candidates << subnets;
+ candidates = {{QHostAddress{"10.0.0.0"}, 8}};
+ subnets = {{QHostAddress{"10.200.100.1"}, 24}};
+ QTest::newRow("2") << candidates << subnets;
+ candidates = {{QHostAddress{"10.9.4.70"}, 22}};
+ subnets = {{QHostAddress{"192.168.12.1"}, 24},
+ {QHostAddress{"172.16.45.1"}, 24},
+ {QHostAddress{"10.9.0.1"}, 16}};
+ QTest::newRow("3") << candidates << subnets;
+}
+
+QTEST_APPLESS_MAIN(tst_Subnet)
+
+#include "tst_subnet.moc"
diff --git a/tests/tst_subnet.pro b/tests/tst_subnet.pro
new file mode 100644
index 0000000..9a5a1bc
--- /dev/null
+++ b/tests/tst_subnet.pro
@@ -0,0 +1,20 @@
+QT -= gui
+QT += network testlib
+
+CONFIG += c++11
+CONFIG += testcase
+
+TARGET = tst_subnet
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+INCLUDEPATH += $$PWD/../
+
+HEADERS += \
+ ../qdb/server/subnet.h \
+
+SOURCES += \
+ ../qdb/server/subnet.cpp \
+ tst_subnet.cpp \