Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 4a9e70db

Přidáno uživatelem Jakub Šilhavý před asi 3 roky(ů)

re #9566 Created mocks for simulating an LD-debugger

Zobrazit rozdíly:

ld_client/Mock/ld/CMakeLists.txt
1
cmake_minimum_required(VERSION 3.0)
2

  
3
project(ld_mock)
4

  
5
set(CMAKE_CXX_STANDARD 17)
6

  
7
add_executable(${PROJECT_NAME} ld_mock.cpp)
ld_client/Mock/ld/ld_mock.cpp
1
#include <chrono>
2
#include <thread>
3

  
4
static constexpr int LOOP_DELAY_S = 10;
5

  
6
int main() {
7
    while (true) {
8
        std::this_thread::sleep_for(std::chrono::milliseconds(LOOP_DELAY_S * 1000));
9
    }
10
    return 0;
11
}
ld_client/Mock/t32rem/CMakeLists.txt
1
cmake_minimum_required(VERSION 3.0)
2

  
3
project(t32rem_mock)
4

  
5
set(CMAKE_CXX_STANDARD 17)
6

  
7
add_executable(${PROJECT_NAME} t32rem_mock.cpp)
ld_client/Mock/t32rem/t32rem_mock.cpp
1
// t32rem.exe localhost port=20000 VERSION.HARDWARE
2
#include <chrono>
3
#include <thread>
4
#include <random>
5
#include <fstream>
6
#include <iostream>
7
#include <cstring>
8

  
9
static constexpr int EXPECTED_NUMBER_OF_ARGUMENTS = 4;
10
static constexpr const char *OUTPUT_FILE_NAME = "output.txt";
11
static constexpr const char *DEBUGGER_INFO =
12
        "B::version.hardware\n"
13
        "PowerDebug USB 3.0 via USB 3.0\n"
14
        "   Serial Number: C21070308132\n"
15
        "   Firmware R.2021.02 (136263)\n"
16
        "   Instance: 1.\n"
17
        "   Automotive Debug Cable\n"
18
        "      Serial Number: C17040231820\n";
19

  
20
static constexpr int MIN_SEC_DELAY = 1;
21
static constexpr int MAX_SEC_DELAY = 10;
22

  
23
int main(int argc, char *argv[]) {
24
    if (argc != EXPECTED_NUMBER_OF_ARGUMENTS) {
25
        std::cout << "Invalid number of arguments\n";
26
        std::cout << "The mock is meant to be called with the following arguments: localhost port=20000 VERSION.HARDWARE\n";
27
        return 1;
28
    }
29
    if (strcmp(argv[1], "localhost") != 0) {
30
        std::cout << "Invalid first argument (expected 'localhost')\n";
31
        return 2;
32
    }
33
    if (strcmp(argv[2], "port=20000") != 0) {
34
        std::cout << "Invalid second argument (expected 'port=20000')\n";
35
        return 2;
36
    }
37
    if (strcmp(argv[3], "VERSION.HARDWARE") != 0) {
38
        std::cout << "Invalid third argument (expected 'VERSION.HARDWARE')\n";
39
        return 2;
40
    }
41

  
42
    std::random_device rd;
43
    std::mt19937 mt(rd());
44
    std::uniform_int_distribution<uint32_t> distribution(MIN_SEC_DELAY, MAX_SEC_DELAY);
45
    uint32_t delay_s = distribution(mt);
46
    std::this_thread::sleep_for(std::chrono::milliseconds(delay_s * 1000));
47

  
48
    std::ofstream file(OUTPUT_FILE_NAME);
49
    if (!file) {
50
        std::cout << "Fail to open the output file\n";
51
        return 3;
52
    }
53
    file << DEBUGGER_INFO;
54
    file.close();
55

  
56
    return 0;
57
}

Také k dispozici: Unified diff