There are two things that make this a tricky question.
The first tricky point is external control and power conversation requirements that can differ between the generation and motoring modes. If you limit the question to permanent magnet commutator or synchronous motors the problem can be simplified. With the DC motor, you can measure the DC power in or out and the speed and torque at the shaft. Similarly with the synchronous motor, you measure AC power in or out and speed and torque at the shaft.
The second tricky point is how to define equivalent operating conditions.
If you run a test with 100 W electrical input to the motor and get 80 W mechanical out, your efficiency is 80 percent The losses are 20 W. Assume that the electrical losses, are 15 W and the mechanical losses, friction and aerodynamic drag, are 5 W.
If you then run a test with 100 W mechanical input, you can expect the mechanical losses to be 5 W, the same as for motoring. You might expect the electrical losses to be 15W and the total output to be 80 W for the same efficiency. However the voltage or current would need to be a little lower for that to be true. With a lower output current, the losses would tend to be lower.
It might make more sense to find operating points where the losses are equal for motoring and generating. Then calculate the efficiency at that point.
The reason that we must say that the efficiency is only approximately the same for motoring as for generating is that we really need to analyze all of the loss components is order to understand the performance. Mechanical losses are proportional to speed or speed raised to some exponent. Torque may contribute by a small factor. Electrical losses are mostly proportional to current with some effect due to voltage and frequency.
Looking at the problem a bit differently:
Assume that the machine under test was sold as a motor. An efficiency test would be run by operating the motor at rated voltage, frequency (for an AC machine) and load torque. The input electrical power and the output torque and RPM would be measured.
To test the machine as a generator, the driving speed and output current can be controlled. The driving speed will determine the output voltage. The output current should not exceed the rated current for motoring operation. The output voltage could exceed the nominal motor voltage, but not by more than the normal operating tolerance, probably 10 percent. The mechanical input power could exceed the rated motor mechanical power as long as the motor remains within the above mentioned voltage and current limits.
When the electrical power is converted to mechanical power in a motor, the electrical and electromagnetic losses occur before the conversion and the mechanical losses occur afterwards. When mechanical power is converted to electrical power in a generator, the mechanical losses occur before the conversion and the electrical and electromagnetic losses occur afterwards.
There is a problem in defining the rated operating point for generator operation if the machine was sold as a motor and vice versa. However, machines are sometimes sold as dual purpose machines. In which case, the manufacturer will make the determination.