changeset 625:f72ad5807857

Add support for building the main test file using scons, linking in gtest.
author ronw@google.com
date Tue, 21 May 2013 21:48:34 +0000
parents 3786bc6e5155
children 586b0677aae8
files carfac/SConstruct carfac/carfac.cc carfac/main.cc
diffstat 3 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/carfac/SConstruct	Tue May 21 20:06:21 2013 +0000
+++ b/carfac/SConstruct	Tue May 21 21:48:34 2013 +0000
@@ -25,8 +25,10 @@
 
 To install dependencies and build on Ubuntu, run:
 
- sudo apt-get install libeigen3-dev scons
+ sudo apt-get install libeigen3-dev scons \
+   cmake libgtest-dev libsndfile-dev  # For testing.
  export EIGEN_PATH=/usr/include/eigen3
+ export GTEST_SOURCE=/usr/src/gtest
  scons
 """
 
@@ -47,3 +49,15 @@
 # Needed to support std::vector initialization lists.
 env.MergeFlags(['-std=c++0x'])
 env.Library(target = 'carfac', source = carfac_sources)
+
+env.Command('tmp/libgtest.a', [],
+            [
+                Delete('tmp'),
+                Copy('tmp', os.environ['GTEST_SOURCE']),
+                'cd tmp && cmake . && make',
+            ])
+
+env.Program(target = 'main',
+            source = ['main.cc'],
+            LIBS = ['carfac', 'sndfile', 'gtest', 'pthread'],
+            LIBPATH = ['.', 'tmp'])
--- a/carfac/carfac.cc	Tue May 21 20:06:21 2013 +0000
+++ b/carfac/carfac.cc	Tue May 21 21:48:34 2013 +0000
@@ -21,6 +21,7 @@
 // limitations under the License.
 
 #include "carfac.h"
+
 void CARFAC::Design(int n_ears, int32_t fs, CARParams car_params,
                     IHCParams ihc_params, AGCParams agc_params) {
   n_ears_ = n_ears;
--- a/carfac/main.cc	Tue May 21 20:06:21 2013 +0000
+++ b/carfac/main.cc	Tue May 21 21:48:34 2013 +0000
@@ -33,11 +33,14 @@
 // linking to the libsndfile.dylib file. Two helper functions 'ReadSound' and
 // 'ReadSoundInfo' are used to obtain header information (needed for the CARFAC
 // design stage) and sound data (for running the model).
+#include <iostream>
+
 #include <sndfile.h>
-#include "carfac.h"
 //GoogleTest is now included for running unit tests
 #include <gtest/gtest.h>
 
+#include "carfac.h"
+
 // ReadSound takes a character array (filename string) as an argument and
 // returns a two dimensional (samples x channels) FloatArray (Eigen ArrayXX)
 // containing the sound data
@@ -106,10 +109,11 @@
   // This initializes the GoogleTest unit testing framework.
   ::testing::InitGoogleTest(&argc, argv);
   // Here we specify a path to a test file.
-  const char * filename = "/Users/alexbrandmeyer/aimc/carfac/test_signal.wav";
+  const char *filename = "test_signal.wav";
   // This loads the header info and sound data.
   SF_INFO info = ReadSoundInfo(filename);
   FloatArray2d mysnd = ReadSound(filename);
+  std::cout << "Read sound from " << filename << std::endl;
   // These initialze the default parameter objects needed for the CARFAC design.
   CARParams *car_params = new CARParams();
   IHCParams *ihc_params = new IHCParams();
@@ -122,8 +126,10 @@
   delete car_params;
   delete ihc_params;
   delete agc_params;
+  std::cout << "Running CARFAC..." << std::endl;
   // Now we run the model on the test data (using a closed loop for now).
   CARFACOutput output = mycf->Run(mysnd, false, true, true, true);
+  std::cout << "done." << std::endl;
   // Finally we clear the CARFAC object when we're done.
   delete mycf;
   return 0;