Home | Projects | Notes > Linux Device Drivers > Exercise 1-3: Pseudo Character Driver (Single Device) - Testing

Exercise 1-3: Pseudo Character Driver (Single Device) - Testing

 

On the Host

  1. Build the kernel module pcd.c against the host Linux kernel version

  2. Insert the mode: sudo insmod pcd.ko

  3. Test the pseudo character driver: echo "Hello, welcome!" > /dev/pcd dmesg

    Output:

    echo command opens the pseudo character device by invoking the open() system call. (L5: pcd_open() gets called from the driver)

    L7: When a file is opened, the current file position is always 0.

    L10: echo invokes close() system call, and subsequently pcd_release() of the driver gets called.

  4. Check the contents of the device (buffer): cat /dev/pcd

    Output:

  5. Check the read activity: dmesg | tail

    L2: Read request for 131072 bytes because that's how the cat program is implemented!

    L5: Updated file position is 512 bytes (i.e., DEV_MEM_SIZE) because that's the size of our buffer.

    L6: cat requests to read again

    L8: 0 bytes since no more to read

  6. Attempt copying a large text file (> 512 Bytes) into /dev/pcd: cp file.txt /dev/pcd

    Output:

    And run dmesg to see what happened:

    L6: 512 bytes successfully written

    L7: The file position reached the end

    L8: cp command attempts to copy the rest of the contents (1717 - 512 = 1205 bytes)

    L9: Since the file position is already at the end, no more write can be done. (pcd_write() returns the error code -ENOMEM which triggers the error message cp: error writing '/dev/pcd': Cannot allocate memory.)