Skip to content

Commit fd501b9

Browse files
committed
[CI] Added test-expect-version tool
1 parent ccf794c commit fd501b9

2 files changed

Lines changed: 120 additions & 0 deletions

File tree

tools/test-expect-version/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CC=gcc
2+
CFLAGS=-Wall -DWOLFSSL_DTLS -DWOLFSSL_DEBUG -DTFM_TIMING_RESISTANT -g -ggdb
3+
EXE=test-expect-version
4+
5+
LIBS=-lwolfssl -lpthread
6+
7+
$(EXE): $(EXE).o
8+
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
9+
10+
clean:
11+
rm -f *.o $(EXE)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/* test-update-server.c
2+
*
3+
* Copyright (C) 2006-2019 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL. (formerly known as CyaSSL)
6+
*
7+
* wolfSSL is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSL is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20+
*
21+
*=============================================================================
22+
*
23+
* OTA Upgrade mechanism implemented using DTLS 1.2
24+
*
25+
*/
26+
27+
#define _XOPEN_SOURCE 600
28+
29+
#include <stdio.h> /* standard in/out procedures */
30+
#include <stdlib.h> /* defines system calls */
31+
#include <string.h> /* necessary for memset */
32+
#include <netdb.h>
33+
#include <sys/socket.h> /* used for all socket calls */
34+
#include <netinet/in.h> /* used for sockaddr_in6 */
35+
#include <arpa/inet.h>
36+
#include <errno.h>
37+
#include <unistd.h>
38+
#include <fcntl.h>
39+
#include <sys/stat.h>
40+
#include <termios.h>
41+
#include <signal.h>
42+
#include <errno.h>
43+
44+
#define MSGLEN (4 + 4 + 8)
45+
#define PORT "/dev/ttyS0"
46+
47+
void alarm_handler(int signo)
48+
{
49+
printf("0\n");
50+
exit(0);
51+
}
52+
53+
54+
55+
int main(int argc, char** argv)
56+
{
57+
struct termios tty;
58+
int res, serialfd;
59+
int star = 0;
60+
int i = 3;
61+
uint32_t ver = 0;
62+
sigset(SIGALRM, alarm_handler);
63+
64+
65+
if (argc != 1) {
66+
printf("Usage: %s\n", argv[0]);
67+
exit(1);
68+
}
69+
70+
serialfd = open(PORT, O_RDWR | O_NOCTTY);
71+
tcgetattr(serialfd, &tty);
72+
cfsetospeed(&tty, B115200);
73+
cfsetispeed(&tty, B115200);
74+
tty.c_cflag = (tty.c_cflag & ~CSIZE) | (CS8);
75+
tty.c_iflag &= ~(IGNBRK | IXON | IXOFF | IXANY| INLCR | ICRNL);
76+
tty.c_oflag &= ~OPOST;
77+
tty.c_oflag &= ~(ONLCR|OCRNL);
78+
tty.c_cflag &= ~(PARENB | PARODD | CSTOPB);
79+
tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
80+
tty.c_iflag &= ~ISTRIP;
81+
tty.c_cc[VMIN] = 0;
82+
tty.c_cc[VTIME] = 5;
83+
tcsetattr(serialfd, TCSANOW, &tty);
84+
85+
alarm(30);
86+
87+
while (i >= 0) {
88+
char c;
89+
res = read(serialfd, &c, 1);
90+
if (res <= 0) {
91+
usleep(10000);
92+
continue;
93+
}
94+
if (!star) {
95+
if (c == '*') {
96+
star = 1;
97+
i = 3;
98+
} else {
99+
star = 0;
100+
}
101+
} else {
102+
ver += (((uint32_t)c) << (i-- * 8));
103+
}
104+
}
105+
printf("%d\n", ver);
106+
close(serialfd);
107+
return 0;
108+
}
109+

0 commit comments

Comments
 (0)