Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #114 (closed defect: fixed)

Opened 2 months ago

Last modified 1 month ago

Unstable / Undocumented Unittest link and runtime behavior

Reported by: jvburnes Assigned to:
Priority: major Milestone:
Component: Version:
Keywords: Cc:

Description

Since I'm interested in moving away from gdc, I decided to build the llvm / ldc toolchain and try it with my D programs.

Once I had everything installed, I changed my build.sh to build my small neural network simulator under ldc instead of gdc. I have unittests enabled in my program.

I kept getting undefined references to the module's unittest components in my build script. I assumed it had something to do with how the modules were being passed in the final link stage.

Here was the build script I used:

echo building netgraph
ldc -c  -unittest netgraph.d -I~/src/ldc/tango -I.
echo building neuron
ldc -c  -unittest neuron.d  -I~/src/ldc/tango -I.
echo building neuralNet
ldc -c -unittest neuralNet.d  -I~/src/ldc/tango -I.
echo building collectest
ldc collectest.d -unittest -I~/src/ldc/tango -I.  netgraph.o neuron.o neuralNet.o
echo done

All of the compiles worked fine, except the last one. It looks liked ldc passed all of the correct arguments to the gcc final link stage (will the release version bypass gcc for link)?

Then I had error messages that said that the linker couldn't resolve the unittests in each module. I tried multiple things to get past this. Eventually I removed the ".o" file extensions in the final ldc build command. Amazingly this worked.

My program ran fine, but the unit tests were run in some strange order and some of them were run multiple times for no apparent reason.

I hope this is just my unfamiliarity with how ldc is setup/runs.

Great project. Good luck. If you CC: me at my gmail account below I'd appreciate it as I don't logon to dsource very often.

Jim Burnes
jvburnes at gmail dot com

Change History

11/12/08 13:52:18 changed by ChristianK

Thanks for the bug report. I can't reproduce it unfortunately.

I'm using three files: test1.d, test2.d, test3.d, all looking like this:

extern(C) int printf(char*, ...);
unittest { printf("Run test<nr>\n"); }

additionally there's empty.d which simply is

void main() {}

and when I run

ldc -c -unittest test1.d
ldc -c -unittest test2.d
ldc -c -unittest test3.d
ldc -c -unittest empty.d test1.o test2.o test3.o

it links fine. When I execute the result, the tests are executed in linking order. What platform are you on? Can you provide a test case?

11/12/08 15:22:48 changed by jvburnes

I knew you were going to ask for a test case :-)

Unfortunately I was running out of drive space today and decided to clean the objs for ldc and llvm. I did a make clean and it unfortunately deleted the binary for 'ldc' too.

I'll do a rebuild and attach the results.

Jim Burnes

11/12/08 16:50:22 changed by jvburnes

Okay, I rebuilt 'ldc'.

Here are the build results with '.o' on the module files:

draco% ./build.sh
building netgraph
building neuron
building neuralNet
building collectest
neuron.o: In function `_D6neuron10__unittestZ':
(.text+0xc54): undefined reference to `_D8netgraph10Connection11__unittest6FZv'
neuron.o: In function `_D6neuron10__unittestZ':
(.text+0xc59): undefined reference to `_D8netgraph4Node11__unittest5FZv'
neuralNet.o: In function `_D9neuralNet10__unittestZ':
(.text+0xb14): undefined reference to `_D8netgraph4Node11__unittest9FZv'
neuralNet.o: In function `_D9neuralNet10__unittestZ':
(.text+0xb19): undefined reference to `_D8netgraph10Connection12__unittest10FZv'
neuralNet.o: In function `_D9neuralNet10__unittestZ':
(.text+0xb23): undefined reference to `_D6neuron11InputNeuron11__unittest5FZv'
neuralNet.o: In function `_D9neuralNet10__unittestZ':
(.text+0xb28): undefined reference to `_D6neuron14LogisticNeuron11__unittest7FZv'
collectest.o: In function `_D10collectest10__unittestZ':
(.text+0xf4): undefined reference to `_D8netgraph10Connection12__unittest10FZv'
collectest.o: In function `_D10collectest10__unittestZ':
(.text+0xf9): undefined reference to `_D8netgraph4Node11__unittest9FZv'
collectest.o: In function `_D10collectest10__unittestZ':
(.text+0xfe): undefined reference to `_D9neuralNet9NeuralNet11__unittest4FZv'
collectest.o: In function `_D10collectest10__unittestZ':
(.text+0x103): undefined reference to `_D6neuron12LinearNeuron11__unittest6FZv'
collect2: ld returned 1 exit status
Error: linking failed:
status: 1
done

Here are the build results when I remove '.o' from the module names:

building netgraph
building neuron
building neuralNet
building collectest
done

Here are the unit test run results after "successful" build. The classes under test are: Node, Connection, LinearNeuron?, InputNeuron?, LinearNeuron?, LogisticNeuron?, BiasNode?, NeuralNet?

testing Node:
testing Connection:
testing NeuralNet:
4 Quadrant Sine -> Logistic Test Pattern
theta	i1	i2	i3	i4	Output
0.00	0.00	0.00	0.00	0.00	  0.50
0.01	0.10	0.00	0.00	0.00	  0.50
... bunch of test data
6.27	0.00	0.00	0.00	-0.10	  0.30
6.28	0.00	0.00	0.00	-0.00	  0.40
NeuralNet tests completed successfully
testing LinearNeuron:
testing Connection:
testing Node:
testing Connection:
testing Node:
testing InputNeuron:
testing LinearNeuron:
testing LogisticNeuron
testing BiasNode:
testing Node:
testing Connection:
testing NeuralNet:
4 Quadrant Sine -> Logistic Test Pattern
theta	i1	i2	i3	i4	Output
0.00	0.00	0.00	0.00	0.00	  0.50
0.01	0.10	0.00	0.00	0.00	  0.50
0.03	0.21	0.00	0.00	0.00	  0.60
... same test data repeated
6.27	0.00	0.00	0.00	-0.10	  0.30
6.28	0.00	0.00	0.00	-0.00	  0.40
NeuralNet tests completed successfully
testing InputNeuron:
testing LogisticNeuron

Some unit tests are obviously being run multiple times, but I'm not sure why.

This is the contents of collectest.d:

import tango.io.Stdout;
import neuralNet;

void main() {
	auto myNet = new NeuralNet();

	auto neuron1 = new LinearNeuron(3,2);

	myNet.addNode(neuron1);
			

I hope this helps someone.

BTW: These are the results before I performed any rebuild.

Jim

11/12/08 17:26:21 changed by jvburnes

I don't know whether this is relevant or not, but one of my modules (neuralNet) does a "public import neuron;" so it can reach the classes that neuron.d imports.

Whether or not this is a good thing to do, I'm not sure. It's supported, but I thought it might be confusing the unittest handler.

11/13/08 07:19:57 changed by lindquist

The import should not break things. It would be useful if you could attach a testcase, ie. the files needed for this to break for you. Then we can check against the same files, which might help a bit.

All my previous tests with unittests and LDC have worked fine...

11/17/08 11:20:36 changed by jvburnes

Perhaps it's the result of an incomplete install. I'll try a re-install.

JB

12/01/08 09:24:16 changed by lindquist

any progress on producing a testcase for this one?

12/04/08 09:31:17 changed by lindquist

there was a bug in moduleinfo that was fixed in rev [824] , it's possible that it had something to do with this, can you please verify that this bug still exists or close it ?

12/07/08 08:14:57 changed by ChristianK

  • status changed from new to closed.
  • resolution set to fixed.

We also fixed a bug in unittests in [830] that was probably responsible for unittests being run more than once. Please reopen if you can still reproduce this bug.

Copyright © 2008, LDC Development Team.