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

feat(ThirdParty): Unity unit test #1033

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

feat(ThirdParty): Unity unit test #1033

wants to merge 12 commits into from

Conversation

EricB-ADI
Copy link
Contributor

@EricB-ADI EricB-ADI commented Jun 3, 2024

Pull Request Template

Description

  • Included 3rd party lib unity for unit testing
  • Added unit test example

@EricB-ADI EricB-ADI added enhancement New feature, request, or updating to latest version help wanted Extra attention is needed WIP work in progress dependencies Pull requests that update a dependency file build system This issue or pull request is related to the MSDK build system labels Jun 3, 2024
@github-actions github-actions bot added MAX32655 Related to the MAX32655 (ME17) Workflow Related to Workflow development labels Jun 3, 2024
@EricB-ADI
Copy link
Contributor Author

EricB-ADI commented Jun 3, 2024

Hey @Jake-Carter , I want to integrate unity into our SDK so we can have, and offer a unit test framework. I have it working ok, but it would benefit a lot more if we can integrate it better into the build system. I updated the libs.mk to include the lib. You can run the tests on target, but it is definitely meant to be ran on the PC. Looking for some pointers or help trying to integrate this better.

@EricB-ADI
Copy link
Contributor Author

/clang-format-run

@Jake-Carter
Copy link
Contributor

Hey @Jake-Carter , I want to integrate unity into our SDK so we can have, and offer a unit test framework. I have it working ok, but it would benefit a lot more if we can integrate it better into the build system. I updated the libs.mk to include the lib. You can run the tests on target, but it is definitely meant to be ran on the PC. Looking for some pointers or help trying to integrate this better.

Sounds good, I'll take a look

@Jake-Carter
Copy link
Contributor

Copy link
Contributor

@Jake-Carter Jake-Carter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EricB-ADI seems easy enough to integrate. Some comments/questions below. Looks like we may need to just assign some custom printing configuration macros to our printf/UART drivers

printf("Hello World!\n");

// This still works but gets stuck with no output on failures
TEST_ASSERT_EQUAL(7, simple_add(3, 4));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


extern uint8_t simple_add(uint8_t x, uint8_t y);
// *****************************************************************************
int main(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should follow the general recommendations for the top-level test structure? (https://github.com/ThrowTheSwitch/Unity/blob/master/docs/UnityGettingStartedGuide.md#how-to-create-a-test-file)

i.e.

int main(void) {
    UNITY_BEGIN();
    RUN_TEST(...);
    // ...
    return UNITY_END();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


TARGET_OUT=testbench
UNITY_DIR=$(LIBS_DIR)/Unity
TEST_SRC=$(UNITY_DIR)/src/unity.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following could probably be handled inside the unity-specific section of unity.mk

UNITY_DIR=$(LIBS_DIR)/Unity
TEST_SRC=$(UNITY_DIR)/src/unity.c
TEST_INC += -I$(LIBS_DIR)/Unity/src


TEST_INC += -I$(LIBS_DIR)/Unity/src

unit:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to just add to SRCS/IPATH/VPATH instead of defining a custom unit target recipe.

Is the motivation to isolate the unit test from the rest of our compiler flags/build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter if they run the unit test on the MCU, but if it uses the same build flags, it will contain the mmcu flag and other arm specific stuff, so you will get gcc errors when targeting your unit test for x86

}

/*=======MAIN=====*/
int main(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this here now... so should we remove our usual main.c file and just run this instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow of running unity while developing is basically when you run make, it builds the project for the target and runs the unit test on the PC so you can quickly test non hardware dependent features. Of course you can test hardware too on target with it, but typically you mock any platform specific stuff just to test the top level.

LIB_UNITY ?= 0
ifeq ($(LIB_UNITY), 1)
LIB_UNITY_DIR ?= $(LIBS_DIR)/Unity
include $(LIB_UNITY_DIR)/unity.mk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you implemented this yet? Would be a good place to manage the central stuff

TEST_CFLAGS += -Wno-unknown-pragmas
TEST_CFLAGS += -Wstrict-prototypes
TEST_CFLAGS += -Wundef
TEST_CFLAGS += -Wold-style-definition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we strictly need this? Related to the question about the custom target recipe

Copy link
Contributor Author

@EricB-ADI EricB-ADI Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Inside the framework is an examples folder, which I originally pulled from. This was just what came with the example. Left it there for now, but it should use as much of the same flags the normal build uses.

@EricB-ADI
Copy link
Contributor Author

Just realized it got added as a submodule and none of the folders are there. Yes I did make a unity.mk.

@EricB-ADI
Copy link
Contributor Author

This should make more sense now.

@EricB-ADI
Copy link
Contributor Author

/clang-format-run

@github-actions github-actions bot added MAX32520 Related to the MAX32520 (ES17) MAX32650 Related to the MAX32650 (ME10) MAX32660 Related to the MAX32660 (ME11) MAX32665 Related to the MAX32665 (ME14) MAX32670 Related to the MAX32670 (ME15) MAX32672 Related to the MAX32672 (ME21) labels Jun 10, 2024
@github-actions github-actions bot added Workflow Related to Workflow development BLE Related to Bluetooth and removed Workflow Related to Workflow development labels Jun 10, 2024
@EricB-ADI
Copy link
Contributor Author

/clang-format-run

@EricB-ADI
Copy link
Contributor Author

@Jake-Carter Everything is working as expected. I reran MSDKGen to update all the makefiles.

@Jake-Carter
Copy link
Contributor

@Jake-Carter Everything is working as expected. I reran MSDKGen to update all the makefiles.

@EricB-ADI can you revert it and just update a single project? My browser crashes now when I try to view the diff

@github-actions github-actions bot removed the BLE Related to Bluetooth label Jun 12, 2024
@github-actions github-actions bot removed MAX32520 Related to the MAX32520 (ES17) MAX32650 Related to the MAX32650 (ME10) MAX32655 Related to the MAX32655 (ME17) MAX32660 Related to the MAX32660 (ME11) MAX32665 Related to the MAX32665 (ME14) MAX32670 Related to the MAX32670 (ME15) MAX32672 Related to the MAX32672 (ME21) MAX32675 Related to the MAX32675 (ME16) MAX32680 Related to the MAX32680 (ME20) MAX78000 Related to the MAX78000 (AI85) MAX78002 Related to the MAX78002 (AI87) MAX32662 Related to the MAX32662 (ME12) labels Jun 12, 2024
@EricB-ADI
Copy link
Contributor Author

@Jake-Carter Everything is working as expected. I reran MSDKGen to update all the makefiles.

@EricB-ADI can you revert it and just update a single project? My browser crashes now when I try to view the diff

done

@github-actions github-actions bot removed the Workflow Related to Workflow development label Jun 12, 2024
Copy link
Contributor

@sihyung-maxim sihyung-maxim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test the example in Keil and IAR (judging by the example's project files)?

If not, I'd recommend deleting those files from the example because it's still TBD how we'll handle IAR and Keil with the SDK. I don't know if we'll continue using the old setup we used to have. Code delivery and setting up a system to sync the codebase for IAR/Keil with GitHub hasn't been officially decided yet (mainly due to a lack of resources).

Also, don't forget to update the boards' examples.txt with the new example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra file?

@sihyung-maxim
Copy link
Contributor

Removed Unity from the linter.

@github-actions github-actions bot added the Workflow Related to Workflow development label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system This issue or pull request is related to the MSDK build system dependencies Pull requests that update a dependency file enhancement New feature, request, or updating to latest version help wanted Extra attention is needed MAX32690 Related to the MAX32690 (ME18) WIP work in progress Workflow Related to Workflow development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants