Method and system for testing program running time in VxWorks real-time system

By obtaining multiple timestamps in VxWorks real-time system and calculating program run time, the problem of not being able to directly obtain program run time is solved, and high-precision run time measurement and timestamp overflow processing are achieved.

CN119415419APending Publication Date: 2025-02-11SHANGHAI AEROSPACE CONTROL TECH INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411292796.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-14
Publication Date
2025-02-11

AI Technical Summary

Technical Problem

In VxWorks real-time system, it is impossible to directly obtain the running time of a certain program, which leads to inconvenience in use.

Method used

Record and calculate the running time of a program by obtaining multiple timestamps in one run cycle, and deal with possible timestamp overflow problems. The specific method includes setting a timer and the main program to run in two threads. The timer gives the running signal to the main program at a set period. The main program obtains the running information based on the running signal and calculates the running time of the program to be tested.

Benefits of technology

It realizes the running time of a program in VxWorks real-time system with a simple and accurate accuracy of up to microseconds, which can effectively deal with the main program cycle error and timestamp overflow problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119415419A_ABST
    Figure CN119415419A_ABST
Patent Text Reader

Abstract

The invention discloses a method and system for testing program running time in a VxWorks real-time system, and belongs to the technical field of spacecraft ground testing. Based on the characteristic that a main program in a real-time system runs in real time in a fixed period, timestamps before and after running of a to-be-tested program and timestamps at the beginning of two main program periods before and after running are obtained, and the running time of the to-be-tested program is obtained by calculating the difference between the timestamps according to an equal proportion principle. The program running time testing method provided by the invention is simple and easy to implement, and can provide reference for program evaluation and optimization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a method and a system for testing program running time in a VxWorks real-time system, belonging to the technical field of spacecraft ground testing. Background Art

[0002] In the design process of the satellite as a whole and each subsystem, a series of real-time tests are required to verify the correctness of the onboard software development and the coordination between software and hardware. In the test, a real-time simulation system is required to run the dynamic simulation program to form a closed-loop system with the onboard software. VxWorks is a real-time operating system designed and developed by WindRiver. It is widely used in real-time tests of satellites for its high real-time performance.

[0003] Running time is an important indicator for measuring program operation and the pros and cons of different implementation methods of the same function. It is of great significance for evaluating and optimizing dynamic simulation programs. The running time of a program cannot be directly obtained in the VxWorks real-time system, which brings inconvenience to its use. Summary of the invention

[0004] The technical problem solved by the present invention is: to overcome the shortcomings of the prior art and provide a method and system for testing the program running time in a VxWorks real-time system, to record and calculate the running time of a certain program by obtaining multiple timestamps within an operating cycle, and to handle the possible timestamp overflow problem.

[0005] The technical solution of the present invention is: a method for testing program running time in a VxWorks real-time system, comprising:

[0006] The timer and the main program are set to run simultaneously in two threads, and the timer gives a running signal to the main program at a set period;

[0007] After the main program is set and run according to the running signal, the running information of the main program and the program to be tested in the main program is obtained;

[0008] Based on the acquired running information, the running time of the program to be tested is calculated according to the principle of equal proportion.

[0009] Furthermore, the timer gives a running signal to the main program at a set period, including: setting and running a timer with a period of Tt, setting a count accumulation in the timer, and adding one to the count every Tt time interval; when the count reaches a preset value, the count is cleared and a running signal is given to the main program.

[0010] Furthermore, the obtaining of the running information of the main program and the program to be tested in the main program includes:

[0011] In one operation cycle, obtain the timestamp TS1 before the program under test runs;

[0012] Run programs that need to be tested on a VxWorks real-time system;

[0013] Get the timestamp TS2 after the program under test runs;

[0014] Record the timestamp TS3last when this cycle starts;

[0015] When the operation signal given by the timer is received, a new operation cycle is entered, and the timestamp TS3 when the new operation cycle starts is obtained.

[0016] Furthermore, the running time of the program to be tested is T=T1 / T2*Tm;

[0017] Among them, when TS2>TS1, T1=TS2-TS1; otherwise, T1=TS2-TS1+TSmax;

[0018] When TS3>TS3last, T2=TS3-TS3last; otherwise, T2=TS3-TS3last+TSmax;

[0019] TSmax is the maximum value of the timestamp related to the hardware, and Tm is the period of the main program.

[0020] Furthermore, the period of the main program and the period Tt of the timer satisfy Tm=N*Tt, where N is a preset value of the timer count.

[0021] A program running time testing system in a VxWorks real-time system, comprising:

[0022] In the first module, a timer and a main program are respectively set to run simultaneously in two threads, and the timer sends a running signal to the main program at a set period;

[0023] The second module sets and runs the main program according to the running signal, and obtains the running information of the main program and the program to be tested in the main program;

[0024] The third module calculates the running time of the program to be tested according to the principle of equal proportion based on the running information of the main program and the program to be tested in the main program.

[0025] Furthermore, the timer gives a running signal to the main program at a set period, including: setting and running a timer with a period of Tt, setting a count accumulation in the timer, and adding one to the count every Tt time interval; when the count reaches a preset value, the count is cleared and a running signal is given to the main program.

[0026] Furthermore, the obtaining of the running information of the main program and the program to be tested in the main program includes:

[0027] In one operation cycle, obtain the timestamp TS1 before the program under test runs;

[0028] Run programs that need to be tested on a VxWorks real-time system;

[0029] Get the timestamp TS2 after the program under test runs;

[0030] Record the timestamp TS3last when this cycle starts;

[0031] When receiving the operation signal from the timer, a new operation cycle is entered, and the timestamp TS3 when the new operation cycle starts is obtained;

[0032] The running time of the program to be tested is T=T1 / T2*Tm;

[0033] Among them, when TS2>TS1, T1=TS2-TS1; otherwise, T1=TS2-TS1+TSmax;

[0034] When TS3>TS3last, T2=TS3-TS3last; otherwise, T2=TS3-TS3last+TSmax;

[0035] TSmax is the maximum value of the timestamp related to the hardware, and Tm is the period of the main program;

[0036] The period of the main program and the period Tt of the timer satisfy Tm=N*Tt, where N is a preset value of the timer count.

[0037] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of a method for testing program running time in a VxWorks real-time system.

[0038] A testing device for program running time in a VxWorks real-time system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that when the processor executes the computer program, the steps of a method for testing program running time in a VxWorks real-time system are implemented.

[0039] The method of the present invention improves the existing technology and can easily and accurately obtain the running time of a certain program running in the VxWorks real-time system, providing a reference for program evaluation and optimization. Compared with the existing technology, the method of the present invention has the following advantages:

[0040] (1) The method of the present invention only needs to obtain relevant timestamps to calculate the program running time, and the method is simple and easy to implement;

[0041] (2) The system timestamp is very accurate. The program running time calculated by the method of the present invention can reach the microsecond level.

[0042] (3) Compared with regarding the main program running cycle as a constant value, the method of the present invention also introduces the timestamp related to the main program running into the program running time calculation, which can effectively deal with the impact of the main program cycle error on the calculated program running time;

[0043] (4) The method of the present invention proposes a solution to the timestamp overflow problem, which can solve the impact of timestamp overflow on the running time of the computing program. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0045] Figure 1 It is a logic block diagram of the timer in the present invention;

[0046] Figure 2 It is the logic block diagram of the main program in the present invention;

[0047] Figure 3 A timing diagram for determining program running time according to the present invention. DETAILED DESCRIPTION

[0048] In order to better understand the above technical scheme, the technical scheme of the present invention is described in detail below through the accompanying drawings and specific embodiments. It should be understood that the embodiments of the present invention and the specific features in the embodiments are detailed descriptions of the technical scheme of the present invention, rather than limitations on the technical scheme of the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.

[0049] The following is a further detailed description of a method for testing the program running time in a VxWorks real-time system provided by an embodiment of the present invention in conjunction with the drawings in the specification. The specific implementation method may include: a timer and a main program, and the two parts run simultaneously in a dual-threaded manner, wherein the period of the timer is Tt, and the period of the main program is Tm, and the two satisfy the relationship Tm=N*Tt, where N is a positive integer.

[0050] Step S1: Set and run the timer

[0051] Set and run a timer with a period of Tt. The timer logic is as follows: Figure 1 As shown. Set the count accumulation in the timer, that is, the count increases by one every Tt time interval. When the count reaches N, the count is cleared and a run signal is given to the main program.

[0052] Step S2: Set up and run the main program

[0053] Set up and run the main program. The main program logic is as follows Figure 2 As shown. After receiving the operation signal given by the timer, the main program enters a new operation cycle. In one operation cycle, the main program will first execute steps S2-6 and S2-7 of the previous operation cycle, and then will execute the following steps in sequence:

[0054] Step S2-1, obtain the timestamp TS1 before the program to be tested runs

[0055] The timestamp before the program under test runs is obtained by calling the sysTimestamp function, which is recorded as TS1.

[0056] Step S2-2: Run the program to be tested

[0057] Run programs that require runtime testing on a VxWorks real-time system.

[0058] Step S2-3, obtain the timestamp TS2 after the program to be tested is run

[0059] The timestamp after the program under test is run is obtained by calling the sysTimestamp function, which is recorded as TS2.

[0060] Step S2-4: Record the timestamp TS3last when this cycle starts

[0061] At the beginning of the current cycle, the main program has obtained the timestamp TS3 at that time by calling the sysTimestamp function. The subsequent timestamp TS3 will be overwritten, so it is assigned to the variable TS3last for use in the next cycle.

[0062] Step S2-5: Wait for the timer to give a running signal

[0063] To ensure that the main program runs with Tm as a cycle, it is necessary to wait for the timer to give a running signal. After receiving the running signal given by the timer, the main program enters a new running cycle and first executes steps S2-6 and S2-7.

[0064] Step S2-6, obtain the timestamp TS3 when the operation cycle starts

[0065] The timestamp at this time is obtained by calling the sysTimestamp function, which is recorded as TS3.

[0066] Step S2-7: Calculate the running time of the program to be tested

[0067] The formula for calculating program running time is:

[0068] T=T1 / T2*Tm

[0069] To deal with possible timestamp overflow, T1 and T2 are calculated as follows:

[0070] When TS2>TS1, T1=TS2-TS1; otherwise, T1=TS2-TS1+TSmax; when TS3>TS3last, T2=TS3-TS3last; otherwise, T2=TS3-TS3last+TSmax. TSmax is the maximum value of the timestamp related to the hardware, which can be determined by obtaining the timestamp multiple times.

[0071] Subsequently, if it is necessary to continue testing the running time of the program to be tested in a new running cycle, the process returns to step S2-1 and continues to sequentially execute steps S2-1 to S2-7.

[0072] Based on the same inventive concept, the present invention also provides a program running time testing system in a VxWorks real-time system, which is characterized by comprising:

[0073] In the first module, a timer and a main program are respectively set to run simultaneously in two threads, and the timer sends a running signal to the main program at a set period;

[0074] The second module sets and runs the main program according to the running signal, and obtains the running information of the main program and the program to be tested in the main program;

[0075] The third module calculates the running time of the program to be tested according to the principle of equal proportion based on the running information of the main program and the program to be tested in the main program.

[0076] The solution provided in the embodiment of the present invention specifically includes:

[0077] Taking the running time of the verification function DemoFun as an example, the timer period is set to Tt=0.2ms, the main program period is set to Tm=2ms, and the ratio of the main program period to the timer period is N=10.

[0078] Therefore, when setting the timer according to the above step S1, set the Count variable in the timer, and after the timer is running, the Count variable is incremented by one every 0.2ms. When Count=10, the timer clears the Count variable and gives a running signal to the main program. Under this design, the interval between two running signals is 2ms, which is exactly the main program cycle.

[0079] After receiving the running signal from the timer, the main program enters a new running cycle (recorded as cycle k). In cycle k, the main program first calls the sysTimestamp function to obtain the timestamp TS3 at the beginning of cycle k, and calculates the running time of the function DemoFun in cycle k-1 based on the timestamp information of the previous running cycle (recorded as cycle k-1).

[0080] In cycle k, the main program will run the function DemoFun again. Before and after running the function, the sysTimestamp function is called to obtain the timestamp at this time, that is, the timestamp before the function runs is TS1, and the timestamp after the function runs is TS2. In addition, since the timestamp TS3 will be overwritten in the next running cycle (recorded as cycle k+1), TS3 is assigned to the variable TS3last for standby.

[0081] After completing all operations, the main program enters waiting mode until it receives a run signal from the timer again and enters cycle k+1. In cycle k+1, the main program first calls the sysTimestamp function to obtain the timestamp TS3 at the beginning of cycle k+1, and calculates the running time of the function DemoFun in cycle k based on the timestamp information TS1, TS2, and TS3last of cycle k, see step S2-7 above.

[0082] like Figure 3 , taking the timestamps TS1 = 150000, TS2 = 155000, TS3 = 30000, TS3last = 140000 as an example, if the test results in TSmax = 220000, the running time is calculated as follows: Since TS2>TS1, T1 = TS2-TS1 = 5000; since TS3>TS3last does not satisfy, T2 = TS3-TS3last+TSmax = 110000. Therefore, the running time of the function DemoFun in cycle k is T = T1 / T2*Tm = 0.0909ms.

[0083] The present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and when the computer instructions are executed on a computer, the computer executes Figure 2 The method described.

[0084] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.

[0085] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0086] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0087] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0088] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

[0089] The contents not described in detail in the specification of the present invention belong to the common knowledge of those skilled in the art.

Claims

1. A method for testing program running time in a VxWorks real-time system, characterized in that: include: The timer and the main program are set to run simultaneously in two threads, and the timer gives a running signal to the main program at a set period; After the main program is set and run according to the running signal, the running information of the main program and the program to be tested in the main program is obtained; Based on the acquired running information, the running time of the program to be tested is calculated according to the principle of equal proportion.

2. A method for testing program running time in a VxWorks real-time system according to claim 1, characterized in that: The timer sends a running signal to the main program at a set period, including: setting and running a timer with a period of Tt, setting a count accumulation in the timer, and adding one to the count every Tt time interval; when the count reaches a preset value, clearing the count and sending a running signal to the main program.

3. The method for testing program running time in a VxWorks real-time system according to claim 1, characterized in that: The obtaining of the running information of the main program and the program to be tested in the main program includes: In one operation cycle, obtain the timestamp TS1 before the program under test runs; Run programs that need to be tested on a VxWorks real-time system; Get the timestamp TS2 after the program under test runs; Record the timestamp TS3last when this cycle starts; When the operation signal given by the timer is received, a new operation cycle is entered, and the timestamp TS3 when the new operation cycle starts is obtained.

4. A method for testing program running time in a VxWorks real-time system according to claim 3, characterized in that: The running time of the program to be tested is T=T1 / T2*Tm; Among them, when TS2>TS1, T1=TS2-TS1; otherwise, T1=TS2-TS1+TSmax; When TS3>TS3last, T2=TS3-TS3last; otherwise, T2=TS3-TS3last+TSmax; TSmax is the maximum value of the timestamp related to the hardware, and Tm is the period of the main program.

5. A method for testing program running time in a VxWorks real-time system according to claim 4, characterized in that: The period of the main program and the period Tt of the timer satisfy Tm=N*Tt, where N is a preset value of the timer count.

6. A program running time testing system in a VxWorks real-time system, characterized by: include: In the first module, a timer and a main program are respectively set to run simultaneously in two threads, and the timer sends a running signal to the main program at a set period; The second module sets and runs the main program according to the running signal, and obtains the running information of the main program and the program to be tested in the main program; The third module calculates the running time of the program to be tested according to the principle of equal proportion based on the running information of the main program and the program to be tested in the main program.

7. A program running time testing system in a VxWorks real-time system according to claim 6, characterized in that: The timer sends a running signal to the main program at a set period, including: setting and running a timer with a period of Tt, setting a count accumulation in the timer, and adding one to the count every Tt time interval; when the count reaches a preset value, clearing the count and sending a running signal to the main program.

8. A program running time testing system in a VxWorks real-time system according to claim 6, characterized in that: The obtaining of the running information of the main program and the program to be tested in the main program includes: In one operation cycle, obtain the timestamp TS1 before the program under test runs; Run programs that need to be tested on a VxWorks real-time system; Get the timestamp TS2 after the program under test runs; Record the timestamp TS3last when this cycle starts; When receiving the operation signal from the timer, a new operation cycle is entered, and the timestamp TS3 when the new operation cycle starts is obtained; The running time of the program to be tested is T=T1 / T2*Tm; Among them, when TS2>TS1, T1=TS2-TS1; otherwise, T1=TS2-TS1+TSmax; When TS3>TS3last, T2=TS3-TS3last; otherwise, T2=TS3-TS3last+TSmax; TSmax is the maximum value of the timestamp related to the hardware, and Tm is the period of the main program; The period of the main program and the period Tt of the timer satisfy Tm=N*Tt, where N is a preset value of the timer count.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.

10. A device for testing program running time in a VxWorks real-time system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.