File Services Sample: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
No edit summary
 
(One intermediate revision by the same user not shown)
Line 24: Line 24:
This example shows how to  use the line-oriented functions - [[File_Transfer_Services#srFileGets|srFileGets]] and [[File_Transfer_Services#srFilePuts|srFilePuts]] - to read and write lines of text.  
This example shows how to  use the line-oriented functions - [[File_Transfer_Services#srFileGets|srFileGets]] and [[File_Transfer_Services#srFilePuts|srFilePuts]] - to read and write lines of text.  


== Run Tests ==
Now launch the test app (if you have not already) and execute the runner with the following commands:
''Test FList tests'':
<pre>
stride --device="TCP:localhost:8000" --database="../out/TestApp.sidb" --run="s2_testflist_basic_fixtures; s2_testflist_basic_simple" --output=FList.xml
</pre>
Note the command will produce distinct result files for the run (per the --output command above). Please use the result file to peruse the results by opening each in your browser.
== Observations ==
The FileServices sample demonstrates basic usage of the [[File_Transfer_Services|STRIDE File Transfer APIs]], which provide a way to transfer files to/from the host to the running device. All the data for the file transmission is done using STRIDE messaging between the STRIDE Runner on the host and the STRIDE Runtime on the device, so no additional communication ports are required to use these services. Review the source code in the directory and follow the sample  description.
The following are some test observations:
* most of the functions return an integer status code which should be checked - any nonzero status indicates a failure. We wrote a macro for this sample (''fsASSERT'') that checks return codes and adds any errors to the report. You might choose to do something similar, depending on your needs.
* the file transfer API has both byte and line oriented read/write functions. You can use whichever functions are most appropriate for your needs.
* this sample uses the local filesystem ([http://en.wikipedia.org/wiki/Stdio stdio]) to write some data to a tempfile - however the STRIDE APIs are themselves buffer/byte oriented and don't require a local filesystem in general. If your device under test ''does'' have a filesystem, the STRIDE APIs can certainly be used to transfer resources to/from the device filesystem.


[[Category: Samples]]
[[Category: Samples]]

Latest revision as of 17:04, 9 June 2011

Introduction

Please read the File Transfer Services article before proceeding in order to understand the concepts.

This example presents a few basic examples of how to use the File Transfer Services API to interact with the host filesystem from test code executing on the device. These services are only available when your code is executing under the control of the STRIDE Runner, such as when you are running Test Units.

Tests Description

CopyHostToTarget

This example shows how to open a file on the host for read access and write all bytes to a local file. We use a temporary file buffer for writing, but any writable stream could be used as a destination.

WriteToHostTempFile

This example shows how to request a temporary file name on the host and write data to the file. We also demonstrate how to use the rename and remove functionality.

SeekAndTell

This example shows how to open a file and seek to a specific location.

ReadAndWriteLines

This example shows how to use the line-oriented functions - srFileGets and srFilePuts - to read and write lines of text.

Run Tests

Now launch the test app (if you have not already) and execute the runner with the following commands:

Test FList tests:

stride --device="TCP:localhost:8000" --database="../out/TestApp.sidb" --run="s2_testflist_basic_fixtures; s2_testflist_basic_simple" --output=FList.xml

Note the command will produce distinct result files for the run (per the --output command above). Please use the result file to peruse the results by opening each in your browser.

Observations

The FileServices sample demonstrates basic usage of the STRIDE File Transfer APIs, which provide a way to transfer files to/from the host to the running device. All the data for the file transmission is done using STRIDE messaging between the STRIDE Runner on the host and the STRIDE Runtime on the device, so no additional communication ports are required to use these services. Review the source code in the directory and follow the sample description.

The following are some test observations:

  • most of the functions return an integer status code which should be checked - any nonzero status indicates a failure. We wrote a macro for this sample (fsASSERT) that checks return codes and adds any errors to the report. You might choose to do something similar, depending on your needs.
  • the file transfer API has both byte and line oriented read/write functions. You can use whichever functions are most appropriate for your needs.
  • this sample uses the local filesystem (stdio) to write some data to a tempfile - however the STRIDE APIs are themselves buffer/byte oriented and don't require a local filesystem in general. If your device under test does have a filesystem, the STRIDE APIs can certainly be used to transfer resources to/from the device filesystem.