Thread: How to generate read/write errors?

  1. #1
    Registered User Kernel Sanders's Avatar
    Join Date
    Aug 2008
    Posts
    61

    How to generate read/write errors?

    I wrote assembly wrappers for read/write system calls for an embedded lab, and now I need to test how it handles errors. How can I generate errors in read/write calls? Short counts I can do, but I don't know how to generate errors. Any ideas?

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Without breaking any micro devices the most common test is buffer overflows. Make sending buffer bigger than the receiving one and vice versa.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not sure what itCbitC is thinking, but I think what you want to do is return a negative value from read/write, and set errno to whatever you want the error to be. You may want to fill the data (when reading) with recognisable rubbish, so that you can detect cases where the read data is being used even tho' it shouldn't be used.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User Kernel Sanders's Avatar
    Join Date
    Aug 2008
    Posts
    61
    Quote Originally Posted by itCbitC View Post
    Without breaking any micro devices the most common test is buffer overflows. Make sending buffer bigger than the receiving one and vice versa.
    Wouldn't I just get a short count?

    Quote Originally Posted by matsp View Post
    Not sure what itCbitC is thinking, but I think what you want to do is return a negative value from read/write, and set errno to whatever you want the error to be. You may want to fill the data (when reading) with recognisable rubbish, so that you can detect cases where the read data is being used even tho' it shouldn't be used.

    --
    Mats
    I already wrote the wrappers, I just have to test the things. When read/write return normally everything works, but I have to test how the wrappers behave when read/write return an error. What I'm asking is how I can create a situation in which read or write would return an error condition

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ah, ok. So that would depend on the situation - what OS is it for [1]? You really need to figure out what will cause the OS to give you a failure back - that may be difficult if you can't control the filesystem/device drivers - you can perhaps pass in NULL as the buffer, but some OS's don't check such things, they rely on the memory management to identify bad memory accesses. If there is memory protection for the code area, you could try to pass the address of a function to the read function, but again, it may just cause a SEGV or it's equivalent.


    [1] This will probably result in some embedded OS that I have never heard of...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    As there is not a whole lot of information about the embedded system I was assuming things and one was to disable a device driven by the microcontroller w/o getting the system into a hung state.
    Apart from that some of the important things would be the installed OS; does it use virtual memory?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template metaprogramming, whats the point?
    By Cogman in forum C++ Programming
    Replies: 26
    Last Post: 02-01-2009, 11:47 PM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  3. Replies: 2
    Last Post: 03-13-2008, 05:45 AM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM