virtual-usb-printer: Replace base::Value::GetList().push_back by Append

base::Value::GetList in r780000 libchrome returns immutable list view.

BUG=chromium:1094927
TEST=unit tests with old and new libchrome

Cq-Depend: chromium:2400408
Change-Id: I567b8b4c12ad2cc69c7dbd8047039572f1c7cd9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/virtual-usb-printer/+/2399166
Tested-by: Grace Cham <hscham@chromium.org>
Tested-by: Kalvin Lee <kdlee@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: Sean Kau <skau@chromium.org>
Reviewed-by: Kalvin Lee <kdlee@chromium.org>
Commit-Queue: Grace Cham <hscham@chromium.org>
Commit-Queue: Qijiang Fan <fqj@google.com>
1 file changed
tree: 16fd1fded20cb204d240fac1532bd6650a3b6299
  1. .clang-format
  2. BUILD.gn
  3. CPPLINT.cfg
  4. LICENSE
  5. OWNERS
  6. PRESUBMIT.cfg
  7. README.md
  8. config/
  9. cups_constants.cc
  10. cups_constants.h
  11. device_descriptors.cc
  12. device_descriptors.h
  13. escl_manager.cc
  14. escl_manager.h
  15. escl_manager_test.cc
  16. http_util.cc
  17. http_util.h
  18. http_util_test.cc
  19. ipp_manager.cc
  20. ipp_manager.h
  21. ipp_manager_test.cc
  22. ipp_util.cc
  23. ipp_util.h
  24. ipp_util_test.cc
  25. load_config.cc
  26. load_config.h
  27. load_config_test.cc
  28. op_commands.cc
  29. op_commands.h
  30. server.cc
  31. server.h
  32. smart_buffer.cc
  33. smart_buffer.h
  34. smart_buffer_test.cc
  35. tools/
  36. usb_printer.cc
  37. usb_printer.h
  38. usbip.cc
  39. usbip.h
  40. usbip_constants.h
  41. value_util.cc
  42. value_util.h
  43. virtual_usb_printer.cc
  44. xml_util.cc
  45. xml_util.h
README.md

Virtual USB Printer

Virtual USB Printer provides a server which can be used with USBIP in order to emulate a USB printing device and bind it to the system as if it were physically connected to a USB port.

Virtual USB Printer supports both regular USB printers as well as IPP-over-USB devices.

Motivation

This project was created in order to make on-device tests which check for any regressions in the native USB printing system.

Requirements

  • USBIP - userspace program for binding virtual device to system
  • USBIP kernel modules:
    • CONFIG_USBIP_CORE
    • CONFIG_USBIP_VHCI_HCD

In order to actually “connect” the virtual printer to the system the USBIP program is used.

USBIP is typically used to export real USB devices over a network so that other systems on the network can bind them and treat them as connected devices.

For the purposes of the virtual printer, only the client portion of USBIP is required so that the virtual device can be bound to the system.

Installation

Currently the USBIP program is only installed by default for the elm and betty boards.

In order to install it on your test image, you need to build an image with the usbip USE flag enabled. To do this, all you need to to is run build_packages with the USE flag enabled.

USE="usbip" ./build_packages --board=$BOARD

How to Use

Run the virtual-usb-printer program:

virtual-usb-printer --descriptors_path=<path>

(Optional) Check the list of exported printers with USBIP:

usbip list -r localhost

Should return something like this:

Exportable USB devices
======================
 - localhost
        1-1: Canon, Inc. : unknown product (04a9:27e8)
           : /sys/devices/pci0000:00/0000:00:01.2/usb1/1-1
           : (Defined at Interface level) (00/00/00)
           : 0 - Printer / Printer Bidirectional (07/01/02)

Bind the virtual printer to the system:

usbip attach -r localhost -b 1-1

Once the device has been attached it should appear in the list of connected USB devices (lsusb), and can be used with the native printing system in Chrome OS.

Configuration

The printer's USB descriptors and defined IPP attributes can be configured using a JSON file and are loaded at run-time using command line flags. Example configurations can be found in the config/ directory.

The configuration files can be loaded with the following flags:

  • --descriptors_path - full path to the JSON file which defines the USB descriptors
  • --attributes_path - full path to the JSON file which defines the supported IPP attributes
    • Only needed for IPP-over-USB printer configurations
  • --record_doc_path - full path to the file used to record documents received from print jobs

Using in Tast

There are currently existing tast tests which leverage virtual-usb-printer in order to test native printing. The following can be used as examples in order to write new tests:

  • Add USB Printer
    • Tests that adding a basic USB printer works correctly
  • Print USB
    • Tests that the full print pipeline works correctly for a basic USB printer
  • Print IPPUSB
    • Tests that the full print pipeline for IPP-over-USB printing works correctly
    • This also tests that the automatic_usb_printer_configurer is able to automatically configure an IPP everywhere printer