OK. The reason I asked is because the loopback test results are inconclusive when using a cheap derivative board with a WCH CH340 chip (in this case the test can fail even with a perfectly functional board). But since your board has the ATmega16U2 chip, we can trust the result of the loopback test.
The test result indicates there is some problem in the ATmega16U2 chip or in the circuit between the chip and pins 0 and 1 on the board (and thus likely between the chip and the primary ATmega328P microcontroller.
It is possible for a short or external circuitry connected to the Arduino board to interfere with the circuit, causing the problems you are experiencing.
Make sure the board is not sitting on anything conductive that could short the contacts on the bottom of the board. Make sure there isn't any conductive debris (e.g., strands of wire or component leads) on the board or on the surface the board is sitting on.
If you have a shield or any external circuitry or components connected to your Arduino board, try this experiment:
- Disconnect the USB cable of the Arduino board from your computer.
- Disconnect any shields, modules, external circuitry, etc. from your board.
- Connect the Arduino board to your computer with a USB cable.
Now try uploading a sketch to the board again. Does the upload succeed?
This experiment will determine whether the upload error was caused by interference from your external circuitry. If so, you can then focus your attention on identifying the specific problem with the circuit and resolving it.