firmware_PDVbusRequest: reject PR_SWAP while testing

This CL disallow the PR_SWAP request from DUT to ensure the
test correctness.

BUG=b:176198744
TEST=ensure the test could pass

Cq-Depend: chromium:2613081
Change-Id: I2f9702899628eacb75bc813b76f5fea6606f67af
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2614246
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Tested-by: Eric Yilun Lin <yllin@chromium.org>
Commit-Queue: Eric Yilun Lin <yllin@chromium.org>
diff --git a/server/cros/servo/pdtester.py b/server/cros/servo/pdtester.py
index a36d85c..4dcdfe9 100644
--- a/server/cros/servo/pdtester.py
+++ b/server/cros/servo/pdtester.py
@@ -33,8 +33,10 @@
     # USB charging command delays in seconds.
     USBC_COMMAND_DELAY = 0.5
     # PDTester USBC commands.
-    USBC_ROLE= 'usbc_role' # TODO(b:140256624): deprecate by USBC_PR
-    USBC_PR= 'usbc_pr'
+    USBC_DRSWAP = 'usbc_drswap'
+    USBC_PRSWAP = 'usbc_prswap'
+    USBC_ROLE = 'usbc_role'  # TODO(b:140256624): deprecate by USBC_PR
+    USBC_PR = 'usbc_pr'
     USBC_MUX = 'usbc_mux'
     RE_USBC_ROLE_VOLTAGE = r'src(\d+)v'
     USBC_SRC_CAPS = 'ada_srccaps'
@@ -225,3 +227,21 @@
                                 'should be either \'dp\' or \'usb\'.' % mux)
         self.set(self.USBC_MUX, mux)
         time.sleep(self.USBC_COMMAND_DELAY)
+
+    def allow_pr_swap(self, allow):
+        """Issue usbc_action prswap PDTester command
+
+        @param allow: a bool for ACK or NACK to PR_SWAP
+                      command requested by DUT
+        @returns value of prswap in PDTester FW
+        """
+        self.set(self.USBC_PRSWAP, allow)
+
+    def allow_dr_swap(self, allow):
+        """Issue usbc_action drswap PDTester command
+
+        @param allow: a bool for ACK or NACK to DR_SWAP
+                      command requested by DUT
+        @returns value of drswap in PDTester FW
+        """
+        self.set(self.USBC_DRSWAP, allow)
diff --git a/server/site_tests/firmware_PDVbusRequest/firmware_PDVbusRequest.py b/server/site_tests/firmware_PDVbusRequest/firmware_PDVbusRequest.py
index 5a7fd16..2dd6f02 100644
--- a/server/site_tests/firmware_PDVbusRequest/firmware_PDVbusRequest.py
+++ b/server/site_tests/firmware_PDVbusRequest/firmware_PDVbusRequest.py
@@ -77,8 +77,12 @@
             # Set the DUT to suspend or shutdown mode
             self.set_ap_off_power_mode(init_power_mode)
         self.usbpd.send_command('chan 0')
+        logging.info('Disallow PR_SWAP request from DUT')
+        self.pdtester.allow_pr_swap(False)
 
     def cleanup(self):
+        logging.info('Allow PR_SWAP request from DUT')
+        self.pdtester.allow_pr_swap(True)
         # Set back to the max 20V SRC mode at the end.
         self.pdtester.charge(self.pdtester.USBC_MAX_VOLTAGE)