[Cook] Cook as a test driver

Henderson, Michael D michael.d.henderson at lmco.com
Sun Nov 23 03:45:19 AEDT 2014


I'm trying to set up Cook to drive tests for legacy code while I'm migrating that code to build under Cook. I'm puzzled by how to set this up initially.

I have tests and each test has one or more steps. Each test uses data from a tarball to test some functionality (all of the steps for a test use the same data). Every test uses a different tarball. The test passes only if all the steps pass, otherwise it fails.

For example:

* test_0000.tar contains two files, a.data and b.data.

* test_0000.pass depends on step_0001.pass and step_0002.pass and step_0003.pass.

* step_0001.pass depends on step_0001.sh and a.data.

* step_0001.sh creates step_0001.log while running. It returns 0 on success, non-zero on error. Cook renames the log file to pass or error based on that status.

* step_0002.pass depends on step_0002.sh and b.data.

* step_0002.sh creates step_0002.log while running. It returns 0 on success, non-zero on error. Cook renames the log file to pass or error based on that status.

* step_0003.pass depends on step_0003.sh and step_0001.pass and step_0002.pass.

* step_0003.sh creates step_0003.log while running. It returns 0 on success, non-zero on error. Cook renames the log file to pass or error based on that status.

* a.data depends on test_0000.tar and is created by tar xf test_0000.tar a.data.

* b.data depends on test_0000.tar and is created by tar xf test_0000.tar b.data.


test_0000.pass: step_0003.pass {
	touch test_0000.pass;
}

step_0003.pass: step_0003.sh step_0001.pass step_0002.pass {
	sh step_0003.sh;
	mv step_0003.log step_0003.pass;
}

step_0001.pass: step_0001.sh a.data {
	sh step_0001.sh;
	mv step_0001.log step_0001.pass;
}

step_0002.pass: step_0002.sh a.data {
	sh step_0002.sh;
	mv step_0002.log step_0002.pass;
}

a.data: test_0000.tar {
	tar xf test_0000.tar a.data;
}

b.data: test_0000.tar {
	tar xf test_0000.tar b.data;
}

(I know that I can consolidate this to something like %.pass: %.sh [%_data] { sh %.sh; mv %.log %.pass; }, but that can wait until after the proof of concept is up and running.)

Is this a good way to organize the hierarchy in cook? I know that it's subjective but I don't think that I'm the first person to use Cook this way. I'd appreciate hearing from someone that's done this before.

How can I handle an expensive operation? Assume for a moment that the tar file really isn't a tar file but a version control system on a remote server and there's a trigger file locally that gets updated when one of the data files that I'm using is updated in that system. (I'm using the tarballs as a proxy until I can figure that part out.) In this scenario, it's cheaper to pull all the files from that system at once rather than query that system to see which files were actually updated. Then the chain becomes "a.data and b.data depend on test_0000.tar and tar xf test_0000.tar always creates a.data and b.data." How could I express that in cook? Wouldn't this be the same as saying that yacc creates both a .c and a .h every time it runs? Cook shouldn't care about what's happening behind the curtains, but it needs to know that the operation updates both files?
 
a.data b.data: test_0000.tar {
	tar xf test_0000 a.data b.data;
}

Thanks,
Mike


More information about the Cook-users mailing list