<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>7833</bug_id>
          
          <creation_ts>2015-06-01 13:38:00 +0000</creation_ts>
          <short_desc>tc.filesdir can&apos;t handle ./files/ folder under other layers</short_desc>
          <delta_ts>2015-08-20 04:33:53 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>10</classification_id>
          <classification>QA/Testing</classification>
          <product>Runtime Testing</product>
          <component>general</component>
          <version>1.8.1</version>
          <rep_platform>All</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>1.9 M2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Cathy Shen">cathy.shen</reporter>
          <assigned_to name="Costin">costin.c.constantin</assigned_to>
          <cc>jing.j.wang</cc>
          
          <qa_contact name="Cathy Shen">cathy.shen</qa_contact>
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Yes (doc changes required)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>51383</commentid>
    <comment_count>0</comment_count>
    <who name="Cathy Shen">cathy.shen</who>
    <bug_when>2015-06-01 13:38:00 +0000</bug_when>
    <thetext>ts.filesdir can&apos;t find the files under ./files/ folder if the test script is under other layer and trying to find the dependency in the ./files/ folder of the same layer.

Currently, we are using workaround:  os.path.join(os.path.dirname(__file__), &apos;files&apos;, &lt;tc_dependent_file_name&gt;)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51520</commentid>
    <comment_count>1</comment_count>
    <who name="Cathy Shen">cathy.shen</who>
    <bug_when>2015-06-05 03:55:38 +0000</bug_when>
    <thetext>JingWang should have a patch to fix this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51536</commentid>
    <comment_count>2</comment_count>
    <who name="jingwang">jing.j.wang</who>
    <bug_when>2015-06-07 23:03:44 +0000</bug_when>
    <thetext>Currently, tc.file_dir is only for /lib/oeqa/runtime/files under oe core layer. For file_dir under other layer, A quick solution is TC itself handle them directly, but not use tc.file_dir.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51537</commentid>
    <comment_count>3</comment_count>
    <who name="Cathy Shen">cathy.shen</who>
    <bug_when>2015-06-08 01:15:24 +0000</bug_when>
    <thetext>Jing, do you mean there is no pacth for this, and are you recomending to use below method in test case? Pls. confirm.
     os.path.join(os.path.dirname(__file__), &apos;files&apos;, &lt;tc_dependent_file_name&gt;)

Constin, as the ticket owner, what&apos;s your comments?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51563</commentid>
    <comment_count>4</comment_count>
    <who name="Costin">costin.c.constantin</who>
    <bug_when>2015-06-08 21:10:52 +0000</bug_when>
    <thetext>Hello Cathy/ Jing,

As the testimage framework is right now, it can accept tests form other layers. Downwards is an example. Before that, i would like to point out that we use meta/lib/oeqa/runtime trying to standardise the way we made tests for our Yocto Project QA purposes.

Example :

PREREQUISITES:
Note, my poky dir is named 3poky 

1) create a new layer with a minimalistic layer.conf file (just for testing purposes in my case)
cosscat@cosscat:/media/cosscat/Touro/3poky/meta-test/conf$ cat layer.conf 
#add to BBPATH
BBPATH .= &quot;:${LAYERDIR}&quot;

2) create lib/oeqa/runtime dir structure with __init__.py in it relative to meta-test path:
cosscat@cosscat:/media/cosscat/Touro/3poky/meta-test/lib/oeqa/runtime$ cat __init__.py 
# Enable other layers to have tests in the same named directory
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

Also add few .py test files here. I added mytest.py and later on 2mytest.py:
cosscat@cosscat:/media/cosscat/Touro/3poky/meta-test/lib/oeqa/runtime$ ls
__init__.py  mytest.py  mytest.pyc

I added intentionally self.assertEqual(1, 0, msg = &quot;This is just for testing purposes ...&quot;) in mytest.py 

3) add meta-test to bblayers.conf:
cosscat@cosscat:/media/cosscat/Touro/3poky/build$ cat conf/bblayers.conf 
...
BBLAYERS ?= &quot; \
  /media/cosscat/Touro/3poky/meta \
  /media/cosscat/Touro/3poky/meta-yocto \
  /media/cosscat/Touro/3poky/meta-yocto-bsp \
  /media/cosscat/Touro/3poky/meta-test \
  &quot;
...

4) inherit testimage.bbclass in local.conf and set TEST_SUITES variable (i will present you my test scenario, using qemux86 as machine):
...
MACHINE ??= &quot;qemux86&quot;
...
EXTRA_IMAGE_FEATURES = &quot;debug-tweaks ssh-server-openssh&quot;

# i used ssh-server-openssh in order to have ssh available in qemu image when building core-image-minimal. 
# it was faster to build an image-minimal than sato and suffices  for our testing purposes

...
CONF_VERSION = &quot;1&quot;
INHERIT += &quot;testimage&quot;
TEST_SUITES = &quot;auto&quot;


5) add support for running commands via sudo without being asked for password (used later on to launch runqemu). This is valid for Ubuntu:
cosscat@cosscat:/media/cosscat/Touro/3poky/build$ sudo visudo
...
# my group name is cosscat. if you want only for a single user, erase the &quot;%&quot;
%cosscat ALL=(ALL) NOPASSWD:ALL


TESTING ITSELF:

Method 1: using the TEST_SUITES = &quot;auto&quot; in local.conf.  

When using TEST_SUITES = &quot;auto&quot; in local.conf the testimage framework will use the __init__.py file found in meta*/lib/oeqa/runtime to automatically add all test .py files it finds here. Thus more layers can be used, the condition being for them to contain a lib/oeqa/runtime dir relative to the meta-name_of_layer. In order for &quot;auto&quot; keyword to work with other layers, i had to do a small change to testimage.bbclass. I will submit a patch for it and let you have it soon.

run the tests itself (in my case just one, from mytest.py):
cosscat@cosscat:/media/cosscat/Touro/3poky/build$ bitbake core-image-minimal -c testimage
...
NOTE: Test modules  [&apos;oeqa.runtime.mytest&apos;]
| NOTE: Found 1 tests
| test_scp_file (oeqa.runtime.mytest.ScpTest) ... FAIL # the name is test_scp_file because mytest.py is a copy of scp.py, with small mods to make it fail
| 
| ======================================================================
| FAIL: test_scp_file (oeqa.runtime.mytest.ScpTest)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
|   File &quot;/media/cosscat/Touro/3poky/meta/lib/oeqa/utils/decorators.py&quot;, line 100, in wrapped_f
|     return func(*args)
|   File &quot;/media/cosscat/Touro/3poky/meta/lib/oeqa/utils/decorators.py&quot;, line 88, in wrapped_f
|     return f(*args)
|   File &quot;/media/cosscat/Touro/3poky/meta-test/lib/oeqa/runtime/mytest.py&quot;, line 20, in test_scp_file
|     self.assertEqual(1, 0, msg = &quot;This is just for testing purposes ...&quot;)
| AssertionError: 1 != 0 : This is just for testing purposes ...
| 
| ----------------------------------------------------------------------
...
 

Method 2: using a list of test names (that correspond to test_names.py from lib/oeqa/runtime):

- you can put the TEST_SUITES variable in local.conf or in a separate file e. test_run.txt:

TEST_SUITES ?= &quot;mytest 2mytest&quot; # created a second file 2mytest 

bitbake core-image-minimal -c testimage   # when setting in local.conf
or
bitbake core-image-minimal -c testimage -r test_run.txt

NOTE: Found 2 tests
| test_scp_file (oeqa.runtime.mytest.ScpTest) ... FAIL
| test_scp_file (oeqa.runtime.2mytest.ScpTest) ... FAIL
| 
| ======================================================================
| FAIL: test_scp_file (oeqa.runtime.mytest.ScpTest)
| ----------------------------------------------------------------------
|...
|     self.assertEqual(1, 0, msg = &quot;This is just for testing purposes ...&quot;)
| AssertionError: 1 != 0 : This is just for testing purposes ...
| 
| ======================================================================
| FAIL: test_scp_file (oeqa.runtime.2mytest.ScpTest)
| ----------------------------------------------------------------------
...
| AssertionError: 1 != 0 :  This is from inside 2mytest.py file
| 
| ----------------------------------------------------------------------
| Ran 2 tests in 4.017s
| 

Please let me know if there is something you would like to know related to adding tests into an other layer.

Costin</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51564</commentid>
    <comment_count>5</comment_count>
    <who name="Costin">costin.c.constantin</who>
    <bug_when>2015-06-08 21:14:36 +0000</bug_when>
    <thetext>Hi Cathy/ Jing,

I forgot to add to my previous comment that i renamed for TEST_SUITES = &quot;auto&quot; the meta/lib/oeqa/__init__.py to something else, preventing the framework to consider tests from this path also. 

Costin</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51770</commentid>
    <comment_count>6</comment_count>
    <who name="Costin">costin.c.constantin</who>
    <bug_when>2015-06-17 20:06:30 +0000</bug_when>
    <thetext>Hi Jing, Cathy,

After trying several possibilities, i came to the conclusion that the way to have files dir available in other meta* layer is by setting the tc.filesdir in the setUpModule() method of each .py test suite file. 
In my case i have a poky/meta-teste/lib/oeqa/runtime/files dir and the oeqa.runtime.test.py looks like:
...
def setUpModule():
    oeRuntimeTest.tc.filesdir = os.path.join(os.path.dirname(os.path.abspath(__file__)),&quot;files&quot;)
...

The approach is similar to comment#3, the difference being we still use  oeRuntimeTest.tc.filesdir

Thank you,

Costin</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>52158</commentid>
    <comment_count>7</comment_count>
    <who name="jingwang">jing.j.wang</who>
    <bug_when>2015-07-07 06:46:24 +0000</bug_when>
    <thetext>This solution looks fine for me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>52951</commentid>
    <comment_count>8</comment_count>
    <who name="Costin">costin.c.constantin</who>
    <bug_when>2015-08-10 14:57:16 +0000</bug_when>
    <thetext>marking as resolved, considering last comment</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>52952</commentid>
    <comment_count>9</comment_count>
    <who name="Costin">costin.c.constantin</who>
    <bug_when>2015-08-10 14:57:45 +0000</bug_when>
    <thetext>marking as verified</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>