Shop OBEX P1 Docs P2 Docs Learn Events
Writing Tests in Drivers and Feedback (MCP9808) — Parallax Forums

Writing Tests in Drivers and Feedback (MCP9808)

geo_leemangeo_leeman Posts: 190
edited 2016-01-16 14:47 in Propeller 1
I'm coming at micro programming from a more Pythonic style data analysis background, so the first thing I wanted to do when writing an object to deal with sensors was write a test-suite for it (to go with the demo). I was curious if there is (which is likely the case) a much more standard/accepted way to test/demo/document your SPIN objects, but this seemed like a reasonable thing to try to do... Test every function and verify it's operation while showing how to use it. I'd appreciate any thoughts or feedback on this approach since I'd like to make sure all of my publicly available code is actually useful to folks. I've attached a screenshot of the demo program output and the code is in a zip file (or on GitHub here). Hmm... That temperature reading seems a bit cold even for a chilly northern day in the shop... I'll have to look at that and see what might be going fishy.

(I can move this to accessories if that's more appropriate, but seemed like a general programming style question to me.)

Comments

  • 12.64°C = 55°F, that about right for an unheated northern workspace in January.

    Nice coding!
  • Heater.Heater. Posts: 21,230
    "test-suite", what ?

    Don't expect much in the way of software engineering practices around here.

    As far as I can tell most objects in OBEX come with some kind of demo wrapped around them which shows how to use it and exercises it's functionality. Which is a good start.

  • MJHanagan wrote: »
    12.64°C = 55°F, that about right for an unheated northern workspace in January.

    Nice coding!

    Thanks! There was actually a small error in the way certain temperature values were handled, but I've got it solved now... and my space heater on!
    Heater. wrote: »
    "test-suite", what ?

    Don't expect much in the way of software engineering practices around here.

    As far as I can tell most objects in OBEX come with some kind of demo wrapped around them which shows how to use it and exercises it's functionality. Which is a good start.

    Well, I'm going to try to make sure things I produce have tests I suppose. A lot of the embedded folks probably don't need them, but I don't trust myself... I've seen my code sometimes! :innocent: It would be great if there were some kind of unit testing framework though!

    I'll probably post on the OBEX, but I (like many others) seem to be putting most things on GitHub these days. Admittedly it doesn't handle spin files very well right now.
  • Nice coding indeed. Also, I was just about to write a driver for MCP9808 myself, but with this tidy code it is not needed.

    Erlend
  • Erlend wrote: »
    Nice coding indeed. Also, I was just about to write a driver for MCP9808 myself, but with this tidy code it is not needed.

    Erlend

    Thanks! I did have an issue with the temp conversion though. I just finished testing it below 0C (thanks to mother nature and cooling spray) and looks like it works a treat now. I'll comment the fixes and put it in the GitHub repo tomorrow, so be sure to use that version! Glad someone will get the benefit of not having to write this!
  • Well done on the unit testing! I only know of two other places in Propeller land that have unit tests and both are C++ (there are probably more, I just haven't run across them yet). The first is SRLM's libpropeller which uses Unity. And the second is PropWare, which uses a homegrown solution. I'm thrilled to see another Prop user doing unit tests!
  • geo_leeman wrote: »

    Thanks! I did have an issue with the temp conversion though. I just finished testing it below 0C (thanks to mother nature and cooling spray) and looks like it works a treat now. I'll comment the fixes and put it in the GitHub repo tomorrow, so be sure to use that version! Glad someone will get the benefit of not having to write this!

    I remember when I wrote my draft code for this chip - I had to dig deep into my brain to recover what I learnt about binary coding of after-the-comma digits. I learnt it at the age of 16 and have not needed it since. Until now. Kindof nice to know that something I learnt four decades ago - in the digital domain - still is 'current'.

    Erlend
  • DavidZemon wrote: »
    Well done on the unit testing! I only know of two other places in Propeller land that have unit tests and both are C++ (there are probably more, I just haven't run across them yet). The first is SRLM's libpropeller which uses Unity. And the second is PropWare, which uses a homegrown solution. I'm thrilled to see another Prop user doing unit tests!

    I almost feel like unit tests are MORE important in embedded since we are more often interacting with and changing the physical world than a typical desktop developer. It would be great if there were a SPIN testing framework that is a bit nicer than my hacky implementation here, but it does do the trick.

    Another nice thing about testing is that it provides the base of tests to go with when setting up your production testing (if that's a thing for your product). I have never done anything high volume, but my instruments are for geophysical applications, so they have to work and have to have good field tests to flag issues.
Sign In or Register to comment.