Setting up a minimal environment for debugging

Hi! I’m very new to Mongoose OS development and was hoping to get my feet wet by compiling the source and running/making my own tests. In particular, I want to investigate how Mongoose’s implementation of cron works (to debug some issues we have with our application that uses it). But I’m unsure how to make a minimal environment to be able to compile and run these tests.

  1. My goal is: to debug a problem in an application by cloning the mongoose-os-libs/cron repository and running tests.
  2. My actions are: I cloned the repository at this address: and was hoping to compile and run the tests located in the test folder.
  3. The result I see is: When I run make on the Makefile in the test folder, I get a bunch of errors related to the fact that there are ../../.. directories leading well outside the repository’s root folder. This is what powershell shows:
PS C:\repos\cron\test> make test                                                                                        gcc --std=c99 -D_POSIX_SOURCE  -I../src -I../include -I../../.. -I../../../frozen -I../../../mongoose -I. -g3 -m32 ../src/mgos_cron.c ../src/ccronexpr.c ../src/sunriset.c ../../../common/cs_time.c ../../../common/str_util.c ../../../common/mg_str.c cs_dbg.c mgos_hal.c mgos_location.c mgos_timers.c mgos_sys_config.c mgos_utils.c ../../../frozen/frozen.c cron_test.c -lm -o cron_test                                                                                                 process_begin: CreateProcess(NULL, gcc --std=c99 -D_POSIX_SOURCE -I../src -I../include -I../../.. -I../../../frozen -I../../../mongoose -I. -g3 -m32 ../src/mgos_cron.c ../src/ccronexpr.c ../src/sunriset.c ../../../common/cs_time.c ../../../common/str_util.c ../../../common/mg_str.c cs_dbg.c mgos_hal.c mgos_location.c mgos_timers.c mgos_sys_config.c mgos_utils.c ../../../frozen/frozen.c cron_test.c -lm -o cron_test, ...) failed.                                                 make (e=2): The system cannot find the file specified.                                                                  make: *** [test] Error 2          
  1. I suppose that this cron repository isn’t meant to be compiled by itself and instead should be part of another project. Would someone be able to point me in the direction of that repository and perhaps give me a few pointers as to how one might get a working environment set up to begin testing functions? Thank you!

Not sure how the tests are run, I don’t see any CI setup in the repo.

You’re probably right, if you want to do anything useful you’ll likely need to follow the basic instructions on getting started with a C/C++ project: Mongoose OS Documentation

I’m guessing you’ll want to clone the c-demo app, not the js app. If you wanted to test the actual cron library on your device, then add the cron library to the mos.yml file in your new project.

I don’t use the cloud compilation service, I build locally which pulls the source files required to build - I’m guessing are required to run the tests based on your comment. If you get stuck there because source files are not being pulled, take a look at mos build locally: the mos build flag you want is --local, but docker is required. You might find this thread handy.

There are a few threads on this forum about speeding things up, but cross that bridge when you get to it.


SOURCES = ../src/mgos_cron.c ../src/ccronexpr.c ../src/sunriset.c \
          ../../../common/cs_time.c \
          ../../../common/str_util.c ../../../common/mg_str.c \
          cs_dbg.c mgos_hal.c mgos_location.c mgos_timers.c \
          mgos_sys_config.c mgos_utils.c ../../../frozen/frozen.c cron_test.c
LIBS = -lm

	gcc --std=c99 -D_POSIX_SOURCE $(CFLAGS) $(INCDIRS) -g3 -m32 $(SOURCES) $(LIBS) -o cron_test

Get all those source files in $(SOURCES) and compile them

Reason: The cron library depends on timers, and tests are not just low-level unit tests but use JSON parsers and other facilities.

If you just want to test the cron library, you’ll have to either remove that or follow Klimbot’s advice and setup a local build environment.

Anyway, if you have a specific issue, report it specifically.

The list of files in the Makefile is obsolete. The file dates from 2018 when the cron library was created. Since than a lot of changes were made.
To make the test compile and run, one should add step by step the needed .h and .c files and clone the relevant repos (mongoose-os, frozen, etc.).

Thanks! I am just realising this fact as I followed the tutorial linked by Klimbot and even after running mos build --platform esp32 --local --verbose I still do not get any kind of directory structure that allows the Makefile to run.

What I think I will try is to make frozen and common folders directly in my local copy of the cron repo, copy the requisite files directly from the mongoose-os directory, and then get the Makefile to point to these folders rather than to the frozen and common folders in some mythical grandparent directory like they currently point.

I will continue working on this and will update this thread later on with what worked (if I manage to get the tests to run).

When you build with --local you have all the dependencies in the deps directory. You can adjust the paths in the Makefile of the cron library.

As an update, cloning the cron repo and then copying in all the files referenced by the Makefile (a la carte from the mjs, mongoose-os, and mongoose repos) does indeed produce a compilable and runnable version of ./cron_test in the test folder of cron. (Here is a link to my fork if you would like to see exactly what I did.)

Unfortunately the tests do not actually pass, but since that is a different issue entirely, I have created a new thread for it, and the main topic of this thread has been resolved.