Imported Upstream version 3.2.2
[debian/gnuradio] / gcell / lib / wrapper / qa_gcell_general.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include "qa_gcell_general.h"
23 #include <cppunit/TestAssert.h>
24
25 #include <stdio.h>
26 #include <stdlib.h>     // random, posix_memalign
27 #include <algorithm>
28 #include <string.h>
29 #include <gcell/gc_job_manager.h>
30
31
32 // handle to embedded SPU executable
33 extern spe_program_handle_t gcell_general_qa_spx;
34
35 gc_job_desc_sptr
36 gcp_qa_general_submit(gc_job_manager_sptr mgr, const std::string &proc_name)
37 {
38   gc_proc_id_t proc_id = mgr->lookup_proc(proc_name);
39   gc_job_desc_sptr jd = gc_job_manager::alloc_job_desc(mgr);
40
41   jd->proc_id = proc_id;
42   jd->input.nargs = 0;
43   jd->output.nargs = 1;
44   jd->eaa.nargs = 0;
45
46   if (!mgr->submit_job(jd.get())){
47     gc_job_status_t s = jd->status;
48     throw gc_bad_submit(proc_name, s);
49   }
50   return jd;
51 }
52
53
54 bool
55 qa_gcell_general::generic_test_body(const std::string &proc_name)
56 {
57   gc_jm_options opts;
58   opts.program_handle = gc_program_handle_from_address(&gcell_general_qa_spx);
59   opts.nspes = 1;
60   gc_job_manager_sptr mgr = gc_make_job_manager(&opts);
61
62   gc_job_desc_sptr jd = gcp_qa_general_submit(mgr, proc_name);
63   if (!mgr->wait_job(jd.get())){
64     fprintf(stderr, "wait_job for %s failed: %s\n",
65             proc_name.c_str(),
66             gc_job_status_string(jd->status).c_str());
67     CPPUNIT_ASSERT(0);
68   }
69
70   return jd->output.arg[0].u32;         // bool result from SPE code
71 }
72
73 /*
74  * ------------------------------------------------------------------------
75  *                  Add more calls to SPE QA code here...
76  * ------------------------------------------------------------------------
77  */
78 void
79 qa_gcell_general::test_memset()
80 {
81   CPPUNIT_ASSERT(generic_test_body("qa_memset"));
82 }
83