Skip to content

Commit 324ae23

Browse files
committed
Add CI and auto-run integration tests
1 parent 37082ae commit 324ae23

7 files changed

Lines changed: 128 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build-and-test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v3
18+
19+
- name: Install Qt5 dependencies
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install -y build-essential cmake qtcreator qtbase5-dev qtserialport5-dev libqt5network5-dev
23+
24+
- name: Install Qt6 dependencies
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install -y qt6-base-dev qt6-serialport-dev libqt6network6-dev
28+
29+
- name: Configure CMake for Qt5
30+
run: cmake -B build_qt5 -DQT_VERSION=5
31+
32+
- name: Build project with Qt5
33+
run: cmake --build build_qt5
34+
35+
- name: Configure CMake for Qt6
36+
run: cmake -B build_qt6 -DQT_VERSION=6
37+
38+
- name: Build project with Qt6
39+
run: cmake --build build_qt6
40+
41+
- name: Compile C test client
42+
run: gcc -o test/test_tcp test/test_tcp.c
43+
44+
- name: Compile C++ test client
45+
run: g++ -std=c++17 -o test/test_tcp_cpp test/test_tcp.cpp
46+
47+
- name: Run Qt5 application and C test
48+
run: |
49+
./build_qt5/qCommTest -p 6666 &
50+
sleep 2 # Give the server time to start
51+
./test/test_tcp
52+
working-directory: ${{ github.workspace }}
53+
54+
- name: Run Qt5 application and C++ test
55+
run: |
56+
./build_qt5/qCommTest -p 6666 &
57+
sleep 2 # Give the server time to start
58+
./test/test_tcp_cpp
59+
working-directory: ${{ github.workspace }}
60+
61+
- name: Run Qt5 application and Python test
62+
run: |
63+
./build_qt5/qCommTest -p 6666 &
64+
sleep 2 # Give the server time to start
65+
python3 test/test_tcp.py
66+
working-directory: ${{ github.workspace }}
67+
68+
- name: Run Qt6 application and C test
69+
run: |
70+
./build_qt6/qCommTest -p 6666 &
71+
sleep 2 # Give the server time to start
72+
./test/test_tcp
73+
working-directory: ${{ github.workspace }}
74+
75+
- name: Run Qt6 application and C++ test
76+
run: |
77+
./build_qt6/qCommTest -p 6666 &
78+
sleep 2 # Give the server time to start
79+
./test/test_tcp_cpp
80+
working-directory: ${{ github.workspace }}
81+
82+
- name: Run Qt6 application and Python test
83+
run: |
84+
./build_qt6/qCommTest -p 6666 &
85+
sleep 2 # Give the server time to start
86+
python3 test/test_tcp.py
87+
working-directory: ${{ github.workspace }}

src/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "mainwindow.h"
88
#include <QApplication>
99
#include <QFile>
10+
#include <QCommandLineParser>
11+
#include <QCommandLineOption>
1012

1113
void setStylesheet()
1214
{
@@ -27,8 +29,29 @@ void setStylesheet()
2729
int main(int argc, char *argv[])
2830
{
2931
QApplication a(argc, argv);
32+
QCoreApplication::setApplicationName("qCommTest");
33+
QCoreApplication::setApplicationVersion("1.0");
34+
35+
QCommandLineParser parser;
36+
parser.setApplicationDescription("Qt Communication Test Tool");
37+
parser.addHelpOption();
38+
parser.addVersionOption();
39+
40+
QCommandLineOption tcpPortOption(QStringList() << "p" << "tcp-port",
41+
QCoreApplication::translate("main", "Start TCP server on <port>."),
42+
QCoreApplication::translate("main", "port"));
43+
parser.addOption(tcpPortOption);
44+
45+
parser.process(a);
46+
3047
MainWindow m;
3148
setStylesheet();
49+
50+
if (parser.isSet(tcpPortOption)) {
51+
int port = parser.value(tcpPortOption).toInt();
52+
m.startTcpServer(port);
53+
}
54+
3255
m.show();
3356
return a.exec();
3457
}

src/mainwindow.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ void MainWindow::onTcpClientDisconnected()
334334
}
335335

336336
void MainWindow::on_tcp_listen_clicked()
337+
{
338+
startTcpServer(ui->tcp_port->value());
339+
}
340+
341+
void MainWindow::startTcpServer(int port)
337342
{
338343
if(m_tcpServer->isListenning())
339344
{
@@ -345,9 +350,7 @@ void MainWindow::on_tcp_listen_clicked()
345350
}
346351
else
347352
{
348-
int serverport = ui->tcp_port->value();
349-
350-
if(false != TcpServer_Start(serverport))
353+
if(false != TcpServer_Start(port))
351354
{
352355
ui->tcp_port->setEnabled(false);
353356
ui->tcp_listen->setText("Stop");

src/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class MainWindow : public QMainWindow
4242
public:
4343
explicit MainWindow(QWidget *parent = 0);
4444
~MainWindow();
45+
void startTcpServer(int port);
4546

4647
private:
4748
Test_Step_t m_testStep;

test/test_tcp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ int main() {
7373
int test_index = 1;
7474
int fail_try = FAIL_TRY_MAX;
7575
unsigned char *response = NULL;
76+
int ret_code = 0;
7677

7778
struct timeval timeout;
7879
timeout.tv_sec = SEND_RECEIVE_TIMEOUT_S;
@@ -135,14 +136,16 @@ int main() {
135136

136137
if (test_index > TEST_INDEX_MAX && fail_try > 0) {
137138
printf("Test passed\n");
139+
ret_code = 0;
138140
} else {
139141
printf("Test failed\n");
142+
ret_code = 1;
140143
}
141144

142145
if (response) {
143146
free(response);
144147
}
145148
close(sock);
146149

147-
return 0;
150+
return ret_code;
148151
}

test/test_tcp.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ int main() {
122122
int test_index = 1;
123123
int fail_try = FAIL_TRY_MAX;
124124
std::vector<unsigned char> response;
125+
int ret_code = 0;
125126

126127
int sock = -1;
127128
while (fail_try > 0) {
@@ -175,14 +176,16 @@ int main() {
175176

176177
if (test_index > TEST_INDEX_MAX && fail_try > 0) {
177178
std::cout << "Test passed" << std::endl;
179+
ret_code = 0;
178180
} else {
179181
std::cout << "Test failed" << std::endl;
182+
ret_code = 1;
180183
}
181184

182185
if (sock != -1) {
183186
close(sock);
184187
}
185188
cleanup_winsock();
186189

187-
return 0;
190+
return ret_code;
188191
}

test/test_tcp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ def run_communication_test():
101101
# Test result
102102
if test_index > TEST_INDEX_MAX and fail_try > 0:
103103
print("Test passed")
104+
return 0
104105
else:
105106
print("Test failed")
107+
return 1
106108

107109
if __name__ == "__main__":
108-
run_communication_test()
110+
exit(run_communication_test())

0 commit comments

Comments
 (0)