That test script is a fairly rigorous test of the UART running at your baudrate (9600), in that it performs simultaneous reading and writing. So I think you can be confident of the ESP32 UART driver. I suspect a hardware problem.
As far as I can see you're left with the following possibilities:
- A fault in the GPS device.
- An error in the GPS device baudrate (unlikely).
- An error in the ESP32 baudrate. Measurements of my ESP32 indicated it was spot-on but you might want to check yours.
- Electrical issues: poor gnd connection, incorrect voltage levels coming from GPS device.
Bear in mind that the test script will work if the ESP32 baudrate is wrong since it is transmitting and receiving on the same UART. Baudrates need to be matched to within 5%. However errors in baudrates are uncommon as oscillators are usually crystal controlled. So I tend towards an electrical problem. You really need to get an oscilloscope or logic analyser onto the data line to diagnose this one.