Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using Stim command in sim_instruction.txt for unit testing (simulator) with xc8 project #682

Open
shabu19 opened this issue Jul 10, 2023 · 1 comment

Comments

@shabu19
Copy link

shabu19 commented Jul 10, 2023

Hi,
I am currently doing unit testing with xc8 compiler on simulator using this project as a baseline.
I was trying to merge an SCL script from MPLABX Stimulus where I am simply setting a pin high and then testing that pin in my test file.
I can easily use Stim command to add an SCL file in sim_instructions.txt file.

Now when I run my test file with ceedling, I can see that the scl script successfully runs before my test file but does not carry the changes to RB0 state in gpio_access.c as it prints out "RB0 is Low".

I am attaching codes below for better understanding.
Output is also attached in the end.

gpio_access.c

int GPIO_SetVar(void)
{
	if(PORTBbits.RB0)
	 	printf("RB0 is High\n");
	else
	 	printf("RB0 is Low\n");

    return 1;
}

test_gpio_access.c

void setUp(void)
{
}

void tearDown(void)
{
}

void test_GPIO_SetVar(void)
{
    int x = GPIO_SetVar();
    TEST_ASSERT_EQUAL(1, x);
}

sim_instructions.txt

device PIC18F26Q10
set oscillator.frequency            32
set oscillator.frequencyunit        Mega
set oscillator.rcfrequency          31
set oscillator.rcfrequencyunit      Kilo
set uart1io.uartioenabled           true
set uart1io.output                  stdout
set uart1io.outputfile              test/simulation/out.txt
set breakoptions.wdtwarnings        Ignore

hwtool sim

program build/ceedling/generated/test/out/test_build.elf

Stim C:\Users\shahbaz.khan\MPLABXProjects\unit_testing\rm3_wifi_ceedling_ut\stimb0.scl
Sleep 5000

Run
Sleep 5000
print pin RB0
Quit

stim_file.scl

// 
// C:\Users\shahbaz.khan\MPLABXProjects\unit_testing\rm3_wifi_ceedling_ut\stimb0.scl
// Generated by Stimulus MPLAB X
// Mon Jul 10 14:20:34 AEST 2023
// 


configuration for "pic18f26q10" is
end configuration;

testbench for "pic18f26q10" is
begin
    // Pin/Register Actions
    process is
    begin
        wait for 0 ic;
        report "Stimulus actions after 0 ic";
        TRISB.TRISB0 <= '1';
        RB0 <= '1';
        wait;
    end process;

end testbench;

output dump

  - ""
  - "Stim C:\Users\shahbaz.khan\MPLABXProjects\unit_testing\rm3_wifi_ceedling_ut\stimb0.scl"
  - ""
  - "Sleep 5000"
  - ""
  - ""
  - "Run"
  - "Running"
  - ""
  - "Sleep 5000"
  - "Stimulus actions after 0 ic"
  - "RB0 is Low"
  - "print pin RB0"
  - "Pin        Mode    Value   Owner or Mapping"
  - "RB0        Ain     5.0V    (RB0)/IOCB0/C2IN1+/ANB0/ZCD"
  - ""
  - "Quit"
  - "Simulator halted"
  - "---debug: Peripheral Accessed - WDT"
  - "---debug: Peripheral Accessed - UART1"
  - "Stop at"
  - "   address:0xede0"
  - "   file:C:/Users/shahbaz.khan/MPLABXProjects/unit_testing/rm3_wifi_ceedling_ut/test/support/support_uart.c"
  - "   source line:45"
  - ""
  - ">---debug: Peripheral Accessed - WDT"
  - "---debug: Peripheral Accessed - UART1"
  - ""

--------------------
OVERALL TEST SUMMARY
--------------------
TESTED:  1
PASSED:  1
FAILED:  0
IGNORED: 0
@AndersonMartins1
Copy link

It appears that the issue is related to the fact that changes made to the RB0 pin state in the SCL script are not correctly reflecting in the gpio_access.c file during the test run.

This could be due to a few reasons:

RB0 Pin Configuration: Verify that the RB0 pin configuration is correct in both the SCL script and the gpio_access.c code. Make sure the pin is correctly configured as an output in the SCL script and is being read correctly in the gpio_access.c code.

Insufficient Waiting Time: The waiting time between stimulating the RB0 pin and running the test may not be enough for changes to the pin to be reflected at the time GPIO_SetVar() is called. Try increasing the wait time between these two steps to ensure the changes have enough time to occur.

Pin State Check: Check if the GPIO_SetVar() function is correctly reading the state of the RB0 pin. There may be a problem reading the pin state that is resulting in the incorrect "RB0 is Low" output.

Try making the following changes to resolve the issue:

Verify that the RB0 pin configuration is correct in the SCL scripts and gpio_access.c code.
Increase the delay time between stimulating the RB0 pin and running the test to ensure that pin changes are reflected.
Verify that the GPIO_SetVar() function is correctly reading the state of the RB0 pin and adjust it as necessary.
If the problem persists after these changes, you may need to do more detailed debugging to identify the root cause of the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants