Repository navigation
Upgrade CI setup (SPI/I2C/PWM/BME280 functional tests) - #758
Conversation
|
On the tests, you can add a led and a photoled connected to face each others. In that case, you'll test simple GPIO both writing and reading. On this: #753 (BME280 does not report pressure correctly when no extra settings passed) i2CBmpe80.SetPowerMode(PowerMode.Forced);
//set samplings
i2CBmpe80.SetTemperatureSampling(Sampling.UltraLowPower);
i2CBmpe80.SetPressureSampling(Sampling.UltraLowPower); |
|
|
||
| using Xunit; | ||
|
|
||
| using static System.Device.Gpio.Tests.SetupHelpers; |
There was a problem hiding this comment.
NIT: this makes the code a bit harder to follow. I would just instead call SetupHelpers.CreateAdc()
There was a problem hiding this comment.
How is that different from creating a base class and using derived member or using partial classes we use everywhere in corefx?
There was a problem hiding this comment.
When just reading the code online, first thing people will look for is a method defined in the class, then they will check if this class has a parent class. Both of those checks will fail to tell you where the method is defined, and the using static statement is not something that is very intuitive to a lot of devs, so given that all you are really saving here is typing about 10 chars, I would personally just do the full SetupHelpers.CreateAdc() for readability.
|
|
||
| namespace System.Device.Gpio.Tests | ||
| { | ||
| public class Mcp3008Tests |
There was a problem hiding this comment.
do we also plan to write tests that actually test the device functionality? I ask because technically we are not really testing in here if SPI is working or not.
There was a problem hiding this comment.
FunctionalTests do test MCP3008
|
|
||
| // assuming that tests are run in the room temperature | ||
| // worst case scenario: it's very hot outside | ||
| Assert.InRange(temperature.Celsius, 15, 40); |
There was a problem hiding this comment.
I would rather not make these kind of assumptions, same goes for the pressure and humidity. The simple fact that we were able to instantiate a bme280 means I2c is working, because as part of the device initialization we check a specific register to make sure we are talking to a bme280 and we throw if that is not the case, so the fact that we were able to create it is proof enough that I2c communication works.
There was a problem hiding this comment.
humidity cannot be outside of 0-100 range since 0 means completely dry and 100 means as humid as it can be. Pressure - unless you're running these tests on the moon or in the center of the massive hurricane I don't expect it to ever fail. For temperature I can increase the lower range but I think anything above 40C might suggest that lab is on fire (we can increase it by a a few degrees either way if anyone complains)
There was a problem hiding this comment.
I would do Math.Max(40, CpuTemp) if sensor is anywhere near the Pi. Heat travels easily on a pcb, like a Pi hat.
There was a problem hiding this comment.
good point, especially we have a binding for the CPU temperature (at least on Linux)
| Thread.Sleep(2); | ||
|
|
||
| int expected = (int)Math.Round(pwm.DutyCycle * 1023.0); | ||
| AdcValueAround(expected, adc.Read(0)); |
There was a problem hiding this comment.
This looks like the sort of test that might be flaky. It's fine to keep it as is for now, but if we start seeing that the test fails some builds we might have to rethink a better way to test pwm.
There was a problem hiding this comment.
Why do you think it would fail? The only time I expect this might fail is:
- input voltage is not stable
- if this is the case we should fix the lab
- something got disconnected or got physically broken (including MCP3008 stopping working)
- legitimate failure which we should fix
- Helix runs multiple tests on the same Pi at the same time
There was a problem hiding this comment.
- I actually have run this test in a loop on my box for some time and no issues
|
|
||
| namespace System.Device.Gpio.Tests | ||
| { | ||
| [Trait("requirement", "root")] |
There was a problem hiding this comment.
Currently all tests run as root already
There was a problem hiding this comment.
In the CI yes but not when I test locally (it's bad practice to ask people to run anything as root if not needed).
I was thinking about this but I didn't want to do it for couple of reasons:
|
0016164 to
56b4969
Compare
|
I've updated to the working without issues state. Feedback hasn't been addressed yet |
|
@joperezr we should figure out what to do with CI on 1.0 branch since it will need to run against the old setup. Perhaps we should leave 1-2 Pis for 1.0 runs? |
Don't we still plan on having two pins connected to each other via a resistor in the new setup? I thought that was the case, and if so, that would mean that the tests would still be able to run on the new configuration right? (perhaps with some pin numbering changes) |
|
fair enough, we can do that |
|
/azp run |
|
Pull request contains merge conflicts. |
|
One small comment is that it would probably be good if we stuff all of the gerber/schematics of the PCB to be in a subfolder inside the tests System.Device.Gpio.Tests folder to not pollute the source files |
|
|
||
| | Component | Quantity | | ||
| | --- | --- | | ||
| | MCP3008 I/SL | 1 | |
There was a problem hiding this comment.
Apart from listing these requirements and showing our PCB, I think it would be useful if we also provided a fritzing diagram since most contributors will probably be using a breadboard to test this. You don't have to block this PR on that, but do at least log an issue so that we add this diagram so people know how to connect each of the components in order for our tests to run without a need to change the code configurations
There was a problem hiding this comment.
there is schematics pdf with description how to connect, I feel fritzing doesn't look any clearer and rather more confusing
| | (optional) 1x4 male header | 4 | | ||
| | (optional) 1x8 male header | 1 | | ||
| | (optional) 200 ohm resistor in 0603 (US) package | 1 | | ||
| | (optional) LED in 0603 (US) package | 1 | |
There was a problem hiding this comment.
Minor: If connecting an LED an additional resistor (~150 Ohms) is required, or this will be a short-living experience...
There was a problem hiding this comment.
I mentioned this line above: | (optional) 200 ohm resistor in 0603 (US) package | 1 | - I usually use 200 ohms for LEDs
There was a problem hiding this comment.
Uh sorry, I have overlooked that line.
|
I'll rerun CI couple of times to make sure nothing (new) is flaky |
|
/azp run |
|
Hmm #832: |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This usually means one of the sensors is not plugged in correctly. It also makes sense if it fails intermittently because it may not run on the same device next time. We should try to figure out which Pi did that failure happen in in order to make sure we reconnect the sensor. |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@joperezr failed again same way, ddvsorpil025 again |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Yup I guess that is expected, I'll try to go to the lab later today or ping the infrastructure people to get it out of the queue. |
|
@joperezr I think it might be worth to just try unplug the PI and plug it back in. I recall had something similar locally once - simple reboot wasn't enough but unplugging was good enough. If that helps perhaps there are some ways to fix this in software |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Ok after sending dozens of jobs I haven't seen any of the I2C issues - only one of the unrelated tests is flaky (testing pull up/down mode). I think we're good with merging this. |
|
And congratulations! Very nice work @krwq on this PR! Automating hardware test is far to be easy especially in a real CI/CD pipeline. |
Fixes: #757
Upgrades CI setup and adds couple of functional and unit tests.
Issues found while testing:
Please make sure to see the Fritzing diagramSee README.md instead, fritzing was replaced with schematics and gerberTesting details:
Do not merge until we actually plug that into CI.
Please let me know what other tests you think I should add or any recommendation to modify the circuit
cc: @ZhangGaoxing @shaggygi @Ellerbach
There is one modification I'm planning to do: test BME280 with both I2C and SPI - that should test scenario with multiple devices connected on SPI. Currently I don't have any multiplexers available and waiting for them to arrive.