The Linux Foundation

 
LSB T2C ALSA MiniTutorial

From The Linux Foundation

Contents


Prerequisites

  1. gcc and make
  2. LSB SDK 4.0.3
  3. TET and TET-devel
  4. bzr

T2C installation

T2C installation process follows traditional 'configure, make, make install' pattern:

wget http://downloads.sourceforge.net/project/template2code/t2c/t2c-2.0_Arnor/t2c-2.0.0_final.tar.bz2
tar xfj t2c-2.0.0_final.tar.bz2
cd t2c-2.0.0_final
./configure
make
sudo make install

ReqMarkup installation

1. Download corresponding ReqMarkup Plugin and extract tgz file.  
2. Start KompoZer.
3. Open "Tools" -> "Add-ons" -> "Extensions" in the main menu.
4. Press "Install" and select reqmarkup-X.Y.Z.xpi (X.Y.Z is a version number).
5. Press "Install" and then restart KompoZer.

Checkout t2c-alsa-tests

Checkout t2c-alsa-tests to a new branch.

# Introduce yourself to bzr if you have not
bzr whoami "Alexey Khoroshilov <khoroshilov@linuxfoundation.org>"
# Checkout t2c-alsa-tests
cd ~/workdir
bzr branch http://bzr.linux-foundation.org/lsb/devel/t2c-alsa-tests t2c-alsa-tests

Develop a test

Select target interface

The prioritized list of interfaces to be tested:

Understand the interface

The documentation to the interface is in t2c-alsa-tests/spec/group___control.html.

int snd_card_next(int* rcard);

Try to determine the next card.

Parameters:
  rcard - pointer to card number
Returns:
  zero if success, otherwise a negative error code

Tries to determine the next card from given card number. 
If card number is -1, then the first available card is returned.
If the result card number is -1, no more cards are available.

Let us consider a system with the only card whose id is 0.

> ls /dev/snd/control*
/dev/snd/controlC0

In this case:

 snd_card_next(-1) ->  0
 snd_card_next(0)  -> -1
 snd_card_next(1)  -> -1
 ...

Unit test

The unit test for snd_card_next() on this system can be:

int main(int argc, const char** argv)
{
  int rcard, res;
  
  rcard == -1;
  res = snd_card_next( &rcard );
  ASSERT( (res == 0) && (rcard == 0) ); 

  rcard = 0;
  res = snd_card_next( &rcard );
  ASSERT( (res == 0) && (rcard == -1) ); 

  rcard = 1;
  res = snd_card_next( &rcard );
  ASSERT( (res == 0) && (rcard == -1) ); 
}

General test case template

// 1. Prepare test situation
// 2. Target call
// 3. Check results
// 4. Deallocate resources

General test case template for snd_card_next

// 1. Prepare test situation
  int rcard, res;
  rcard = -1;
// 2. Target call
  res = snd_card_next( &rcard );
// 3. Check results
  ASSERT( (res == 0) && (rcard == 0) ); 
// 4. Deallocate resources
  // Not required here

T2C format

<BLOCK>
<TARGETS>
  snd_card_next
</TARGETS>

<CODE>
// 1. Prepare test situation
  int rcard, res;
  rcard = -1;
// 2. Target call
  res = snd_card_next( &rcard );
// 3. Check results
  ASSERT( (res == 0) && (rcard == 0) );
// 4. Deallocate resources
  // Not required here

// 1. Prepare test situation
  rcard = 0;
// 2. Target call
  res = snd_card_next( &rcard );
// 3. Check results
  ASSERT( (res == 0) && (rcard == -1) );
// 4. Deallocate resources
  // Not required here
</CODE>
</BLOCK>

Please note, sequence of test cases inside of one <BLOCK> is NOT recommended.

T2C format: parameterization

<BLOCK>
<TARGETS>
  snd_card_next
</TARGETS>

<DEFINE>
  #define VALUE     <%0%>
  #define EXPECTED  <%1%>
</DEFINE>
<CODE>
// 1. Prepare test situation
  int rcard, res;
  rcard = VALUE;
// 2. Target call
  int res = snd_card_next( &rcard );
// 3. Check results
  ASSERT( (res == 0) && (rcard == EXPECTED) ); 
// 4. Deallocate resources
  // Not required here
</CODE>
<VALUES>
  -1
  0
</VALUES>
<VALUES>
  0
  -1
</VALUES>
<VALUES>
  1
  -1
</VALUES>
</BLOCK>

What to check?

int snd_card_next(int* rcard);

{01}Try to determine the next card.{/01}

Parameters:
  rcard - {02}pointer to card number{/02}
Returns:
  {03}zero if success,{/03} {04}otherwise a negative error code{/04}

{05}Tries to determine the next card from given card number.{/05}
{06}If card number is -1, then the first available card is returned.{/06}
{07}If the result card number is -1, no more cards are available.{/07}

What to check? (2)

int snd_card_next(int* rcard);

{01}Try to determine the next card.{/01}

Parameters:
  rcard - {02}pointer to card number{/02}
Returns:
  {03}zero if success,{/03} {04}otherwise a negative error code{/04}

{01.01}Tries to determine the next card from given card number.{/01.02}
{01.02}If card number is -1, then the first available card is returned.{/01.02}
{07}If the result card number is -1, no more cards are available.{/07}

What to check? (3)


// 1. Prepare test situation
  int rcard, res;
  rcard = VALUE;
// 2. Target call
  res = snd_card_next( &rcard );
// 3. Check results
  ASSERT( {03}(res == 0){/03} && {01&02&07}(rcard == EXPECTED){/01&02&07} ); 
// 4. Deallocate resources
  // Not required here

What to check? (4)


// 1. Prepare test situation
  int rcard, res;
  rcard = VALUE;
// 2. Target call
  res = snd_card_next( &rcard );
// 3. Check results
  ASSERT( {03}(res == 0){/03} );
  if      ((VALUE != -1) && (rcard != -1))
    ASSERT( {01.01&02}(rcard == EXPECTED){/01.01&02} );
  else if ((VALUE != -1) && (rcard == -1))
    ASSERT( {01.01&02&07}(rcard == EXPECTED){/01.01&02&07} );
  else if ((VALUE == -1) && (rcard != -1))
    ASSERT( {01.02&02}(rcard == EXPECTED){/01.02&02} );
  else if ((VALUE == -1) && (rcard == -1))
    ASSERT( {01.02&02&07}(rcard == EXPECTED){/01.02&02&07} );
// 4. Deallocate resources
  // Not required here

What to check? (5): Markup naming scheme

int snd_card_next(int* rcard);

{snd_card_next.01}Try to determine the next card.{/01}

Parameters:
  rcard - {snd_card_next.02}pointer to card number{/02}
Returns:
  {snd_card_next.03}zero if success,{/03} 
  {snd_card_next.04}otherwise a negative error code{/04}

{snd_card_next.01.01}Tries to determine the next card from given card number.{/01.02}
{snd_card_next.01.02}If card number is -1, then the first available card is returned.{/01.02}
{snd_card_next.07}If the result card number is -1, no more cards are available.{/07}
  1. Open t2c-alsa-tests/spec/group___control.html in Kompozer and markup these requirements.
  2. Generate T2C template for snd_card_next.
  3. Open alsa-t2c/ALSA-t2c/src/ALSA_Control_Interface.t2c in an editor, find a section for snd_card_next and put code there.

What to check? (6): T2C REQ

<CODE>
// 1. Prepare test situation
  int rcard, res;
  rcard = VALUE;
// 2. Target call
  res = snd_card_next( &rcard );
// 3. Check results
  ASSERT( {03}(res == 0){/03} );
  REQ( "snd_card_next.03", "", (res == 0) );
  if ((VALUE != -1) && (rcard == -1))
  {
    ASSERT( {01.01&02}(rcard == EXPECTED){/01.01&02} );
    REQ( "snd_card_next.01.01;snd_card_next.02", "", (rcard == EXPECTED) );
  }
  else if ((VALUE != -1) && (rcard == -1))
  {
    ASSERT( {01.01&02&07}(rcard == EXPECTED){/01.01&02&07} );
    REQ( "snd_card_next.01.01;snd_card_next.02;snd_card_next.07", "", (rcard == EXPECTED) );
  }
  else if ((VALUE == -1) && (rcard != -1))
  {
    ASSERT( {01.02&02}(rcard == EXPECTED){/01.02&02} );
    REQ( "snd_card_next.01.02;snd_card_next.02", "", (rcard == EXPECTED) );
  }
  else if ((VALUE == -1) && (rcard == -1))
  {
    ASSERT( {01.02&02&07}(rcard == EXPECTED){/01.02&02&07} );
    REQ( "snd_card_next.01.02;snd_card_next.02;snd_card_next.07", "", (rcard == EXPECTED) );
  }
// 4. Deallocate resources
  // Not required here
</CODE>

T2C REQ: A little bit theory

<CODE>
// 2. Target call
  int buffer = malloc(1024);
  if (buffer == NULL) ABORT_TEST("Not enough memory");
  int* res = XXX_call( buffer );
// 3. Check results
  REQ( "XXX_call.01", "", (res != NULL) );      // If REQ failed the following checks are not executed,
  REQ( "XXX_call.02", "", (*res == EXPECTED) ); // but the code in FINALLY is executed
// 4. Deallocate resources
  // Not required here
</CODE>
<FINALLY>
  free(buffer);
</FINALLY>

What to check? (7): Simplification

<CODE>
// 1. Prepare test situation
  int rcard, res;
  rcard = VALUE;
// 2. Target call
  res = snd_card_next( &rcard );
// 3. Check results
  REQ( "snd_card_next.03", "", (res == 0) );
  REQ( "snd_card_next.01;snd_card_next.02;snd_card_next.07", "", (rcard == EXPECTED) );
// 4. Deallocate resources
  // Not required here
</CODE>

Compile the test in debug mode and run it

cd t2c-alsa-tests/alsa-t2c
t2c --target=c_minimal ALSA-t2c ALSA-t2c/src/ALSA_Control_Interface.t2c
CC=/opt/lsb/bin/lsbcc make -C ALSA-t2c/tests/ALSA_Control_Interface debug
./ALSA-t2c/tests/ALSA_Control_Interface/ALSA_Control_Interface

Put the test into unknown environment

Let us consider a system with the only card whose id is 0.

<BLOCK>
<TARGETS>
  snd_card_next
</TARGETS>

<DEFINE>
  #define VALUE     <%0%>
  #define EXPECTED  <%1%>
</DEFINE>
<CODE>
// 1. Prepare test situation
  int rcard, res;
  rcard = VALUE;
// 2. Target call
  res = snd_card_next( &rcard );
// 3. Check results
  REQ( "snd_card_next.03", "", (res == 0) );
  REQ( "snd_card_next.01;snd_card_next.02;snd_card_next.07", "", ((rcard == -1) || (rcard > VALUE)) );
// 4. Deallocate resources
  // Not required here
</CODE>
<VALUES>
  -1
  0
</VALUES>
<VALUES>
  0
  -1
</VALUES>
<VALUES>
  1
  -1
</VALUES>
</BLOCK>

Is requirements coverage complete?

What is about snd_card_next.04?

Returns:
  {snd_card_next.03}zero if success,{/03}
  {snd_card_next.04}otherwise a negative error code{/04}
<BLOCK>
<TARGETS>
  snd_card_next
</TARGETS>

<DEFINE>
  #define VALUE     <%0%>
</DEFINE>
<CODE>
// 1. Prepare test situation
  int rcard, res;
  rcard = VALUE;
// 2. Target call
  res = snd_card_next( &rcard );
// 3. Check results
  if (res < 0)
  {
    REQ( "snd_card_next.04", "", (res < 0) );
  }
  else
  {
    REQ( "snd_card_next.03", "", (res == 0) );
    REQ( "snd_card_next.01;snd_card_next.02;snd_card_next.07", "", ((rcard == -1) || (rcard > VALUE)) );
  }
// 4. Deallocate resources
  // Not required here
</CODE>
<VALUES>
  -1
</VALUES>
<VALUES>
  0
</VALUES>
<VALUES>
  1
</VALUES>
</BLOCK>

T2C SET feature

<BLOCK>
<TARGETS>
  snd_card_next
</TARGETS>

<DEFINE>
  #define VALUE     <%0%>
</DEFINE>
<CODE>
// 1. Prepare test situation
  int rcard, res;
  rcard = VALUE;
// 2. Target call
  res = snd_card_next( &rcard );
// 3. Check results
  if (res < 0)
  {
    REQ( "snd_card_next.04", "", (res < 0) );
  }
  else
  {
    REQ( "snd_card_next.03", "", (res == 0) );
    REQ( "snd_card_next.01;snd_card_next.02;snd_card_next.07", "", ((rcard == -1) || (rcard > VALUE)) );
  }
// 4. Deallocate resources
  // Not required here
</CODE>
<VALUES>
  SET(-1 .. 33)
</VALUES>
</BLOCK>

Send the patches to LSB workgroup

After you finish debugging the test, send it to the LSB workgroup.

cd t2c-alsa-tests
bzr commit -m "Updated markup for snd_card_next" spec/group___control.html
bzr commit -m "Normal tests for snd_card_next" alsa-t2c/ALSA-t2c/src/ALSA_Control_Interface.t2c
bzr send -o ~/snd_card_next.patch

Send ~/snd_card_next.patch to LSB discuss mailing list.

Run the whole test suite

If you would like to run the full test suite, you may follow the following instructions:

cd $t2c-alsa-tests$/alsa-t2c
sh ./gen_files.sh c_tet
CC=/opt/lsb/bin/lsbcc ./configure --prefix=`pwd`/_install
export TET_ROOT=/opt/lsb-tet3-lite/
make
make install
cd ./_install/t2c-alsa-tests
./run_tests.sh

[Article] [Discussion] [View source] [History]